Home » vue » Vue router url could not open page

Vue router url could not open page

Posted by: admin November 26, 2021 Leave a comment

Questions:

I am using Vue(“vue”: “^2.5.2”) to make a SPA,this is my route(“vue-router”: “^3.0.1”):

routes: [
    {
      path: '/',
      name: 'Home',
      component: Home
    }]

when I request : http://localhost:8080.It could open the page.But when I tweak the route like this:

routes: [
        {
          path: '/home',
          name: 'Home',
          component: Home
        }]

And I request : http://localhost:8080/home .It could not open the page.Why would this happen ,how to fix it?

Answers:

As stated in the vue router docs:

The default mode for vue-router is hash mode – it uses the URL hash to simulate a full URL so that the page won’t be reloaded when the URL changes.

You should find your page at http://localhost:8080/#/home

You can read more about this here