i have a host with two app reactjs in my host
host->certmanager/…file code reactjs builed
host->cer/… filecode reactjs builed
<Router basename='/certmanager'>
<ThemeModeProvider> {/* Bọc ứng dụng với ThemeModeProvider */}
<AuthProviderWithNavigate>
<ModalProvider>
<Header />
<div>
<Routes>
<Route path="/Login" element={<SignIn />} />
<Route path="/Reset/:code" element={<ResetPassword />} />
<Route path="/Register" element={<Register />} />
<Route path="*" element={<NotFound />} />
<Route element={<PrivateRoutes />}>
<Route path="/" element={<HomePage />} />
<Route path="/group" element={<Group />} />
<Route path='/myinfo' element={<Myinfo />} />
<Route element={<PrivateType_Admin />}>
<Route path="/info" element={<InfoList />} />
</Route>
</Route>
</Routes>
</div>
<BottomNav />
</ModalProvider>
</AuthProviderWithNavigate>
</ThemeModeProvider>
</Router>
in my package-lock.json-> "homepage": "https://abc.or/certmanager/",
when i go to abc.com/certmanager, i will go to abc.or/certmanager/Login(because i need to
login)
const PrivateRoutes = () => {
const { isAuthenticated } = useAuth();
if (!isAuthenticated) {
return <Navigate to="/Login" replace />;
}
return <Outlet />;
};
but when i paste full link abc.or/certmanager/Login into url, i go to 404 not found?
what should i do? thank you….
2
Answers
Here are the issues, I could see.
If that still persists then it might be that your server config-file(maybe nginx if you are using this) does not allow traffic, or does not follow the same
/path/to/your/build/folder;
If you are getting routing errors it might be a case of adding this to your
base ref
. This allows React app to it’s served from a subdirectory(/certmanager)
. Add the following tag below:Alternatively
You are recommended to use newer features of react-router-dom to prevent issues like this. Consider using actions and loaders to simplify building and avoid these bugs.
in your action function, you can simply return a redirect:
While your router looks like this:
See tutorial