When using nuxt2 I need /index as part of the URL
P粉635509719
P粉635509719 2023-09-12 19:54:51
0
1
641

Task request path rendering xxx.com/index/news, xxx.com/index/User For this effect, I set the file tree to:

pages/
--| index/
-----| News/
-------| index.vue
-----| User/
-------| index.vue
--| index.vue

But I cannot successfully jump to other pages except the root directory.

What do I need to do to make the path of the web page display the desired effect?

P粉635509719
P粉635509719

reply all(1)
P粉486138196

The

home page (located in the root path) can safely be named index.vue, there is no other way to bind the page to the / path.

But the problem is indeedYou cannot have a page and a folder with the same name at the same time. They will overlap.

The solution could be to use a custom route in nuxt.config.js to map the root path / to your homepage:

router: {
  extendRoutes (routes, resolve) {
     routes.push(
        {
          name: 'index_home',
          path: '/',
          component: resolve(__dirname, 'pages/home.vue')
        },
     )
  }
},

Seenuxt.config.js/routerDocumentation

Note: You can also delete the automatically created /home route from here, it will be in the routes array.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template