I using react-router-dom v6. But when i want navigate its going to loop. I just want if url isnt one of that routes just navigate to "foo" url. In v5 version i can do it easily with redirect. But in v6 havent redirect so i must use navigate. But its making loop. My code :
const Login = React.lazy(() => import("./login"));
export const AppViews = () => {
return (
<Suspense fallback={<p>Loading...</p>}>
<Routes>
<Route path={`${AUTH_PREFIX_PATH}/login`} element={<Login />} />
<Route
path="*"
element={<Navigate to={`${AUTH_PREFIX_PATH}/login`} replace />}
/>
</Routes>
</Suspense>
);
};
export default AppViews;
What is wrong in that code i really cant figure out. When path is /auth/login shouldn't it open element Login basicly? Its going loop when i make like this. Thank you for replies!
<Route path="*" element={<Navigate to={.....} replace />} />
is the v6 equivalent of the v5Redirect
component, it should works the same for the most part. – Drew Reese