Answer the question
In order to leave comments, you need to log in
Is it correct to route in React via if (switch)?
switch (document.location.pathname) {
case '/': {
ReactDOM.render(
<Index />,
document.getElementById('root'),
);
break;
}
default: {
ReactDOM.render(
<h1>Error</h1>,
document.getElementById('root'),
);
}
}
Answer the question
In order to leave comments, you need to log in
If I understand correctly what you want, that is, to make a processing page if the route is not found, then this is not done this way. Use the prebuilt reactrouter library. First, define a component and a path="*" route for the 404 page. Your solution is here https://reactrouter.com/web/example/no-match
Forgot to mention and you tried https://github.com/vitejs/ vite-plugin-react-pages ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question