T
TanStack2y ago
optimistic-gold

dist/Index.html shows route not found after vite build in dist folder

Hi after i run vite build, and try to load index.html with live server, the __root folder will load properly with all the components(including outlet component), however outlet component will just show the defaultNotFoundComponent defined in the createRouter, if i set the defaultNotFoundComponent as a <Link/> element to other routes, it will load the route properly. what should i do to get the outlet to load the route properly when the webpage first loads from index.html? the defaultNotFoundComponent, the Link works perfectly to load the route:
No description
No description
5 Replies
optimistic-gold
optimistic-goldOP2y ago
Under the routes folder i also have index.tsx which has the '/' route, which is what i want the outlet to first load, but it shows defaultNotFoundComponent instead
No description
flat-fuchsia
flat-fuchsia2y ago
please provide a minimal complete example by forking on of the existing examples on stackblitz
optimistic-gold
optimistic-goldOP2y ago
https://stackblitz.com/edit/vitejs-vite-tesdvu?file=src%2Fmain.tsx I replicated the dev code on stackblitz, dev mode works fine, but when i do 'npm run build' on vscode and then open the dist/index.html with vscode live server, it will show the route not found component unless i provide a way to link to another page inside notfoundComponent, to replicate you will have to download it into vscode and do npm run build and open the dist/index.html with liveserver Also this is probably a problem with vite but under dist/index.html after you do npm run build, make sure the script source is src="./assets/index-CCcrIDlY.js" instead of src="/assets/index-CCcrIDlY.js" , if there is no period at the front the file wont load.
zaaoak
StackBlitz
Tanstack Router - StackBlitz
Next generation frontend tooling. It's fast!
flat-fuchsia
flat-fuchsia2y ago
why do you even use vscode liveserver instead of vite server?
optimistic-gold
optimistic-goldOP2y ago
I use vite server for dev mode, was testing out the dist/index.html with live server, i tried it with vite server for dist/index.html too but it has the same RouteNotFound on initial load

Did you find this page helpful?