Blockquote
How do I route to the next page or another page using VITE?
I have the same problem, using vite
, to redirect to another page we need to import the following lib:
import { navigate } from 'vite-plugin-ssr/client/router';
Don't need to create const variables, but have a caveat, this just work using Client Routing
, on the other hand, you can use:
window.location.href = YOUR ROUTE
See the documentation for more information.
In Vercel this can be done by adding a rewrite to config file in the root of the project called
vercel.json
https://vercel.com/docs/configuration Add rewrites for all routes to the file that point to '/' or '/index.html'
{
"rewrites": [{ "source": "/(.*)", "destination": "/" }]
}
or
{
"rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
}
Refence: Vite.js React Build Not Redirecting On Netlify And Vercel
All your routing can be done via react-router-dom
Use Navigate
, Redirect
or useNavigate
provided by react-router-dom
Please go through the docs and try to implement before asking