Skip to content Skip to sidebar Skip to footer

Vue-router Showing Blank Page When Built

I'm asking for help. I use vuejs to make my application. Everything works perfectly. But I do the npm run build, I extract the dist folder and I open index.html, I have a blank pa

Solution 1:

You're using history mode for your router, which means you'll access your pages with paths like /login or /dashboard or /dashboard/personnel/professeurs, which are the only routes you declared.

/ or /index.html does not display anything because the router doesn't know what they are.

However, in order to have history mode working, you cannot just have a static server. The server has to know that a request to /dashboard should return the index.html file.

If you used VueCLI, the docs here might be helpful:

If you are using Vue Router in history mode, a simple static file server will fail. For example, if you used Vue Router with a route for /todos/42, the dev server has been configured to respond to localhost:3000/todos/42 properly, but a simple static server serving a production build will respond with a 404 instead.

To fix that, you will need to configure your production server to fallback to index.html for any requests that do not match a static file. The Vue Router docs provides configuration instructions for common server setups.

If you don't want to deal with this, or don't have a server enabling you to do this, you can switch history to hash mode in your router. Your routes will be accessible at /index.html#/dashboard and so on.

Post a Comment for "Vue-router Showing Blank Page When Built"