Spec-Zone.ru › Vue Router 3

Named Routes

Learn how to use named routes and params with a free lesson on Vue School

Sometimes it is more convenient to identify a route with a name, especially when linking to a route or performing navigations. You can give a route a name in the routes options while creating the Router instance:

const router = new VueRouter({
  routes: [
    {
      path: '/user/:userId',
      name: 'user',
      component: User
    }
  ]
})

To link to a named route, you can pass an object to the router-link component's to prop:

<router-link :to="{ name: 'user', params: { userId: 123 }}">User</router-link>

This is the exact same object used programmatically with router.push():

router.push({ name: 'user', params: { userId: 123 }})

In both cases, the router will navigate to the path /user/123.

Full example here.

← Programmatic Navigation Named Views →

© 2013–present Evan You
Licensed under the MIT License.
https://router.vuejs.org/guide/essentials/named-routes.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API