vue-router
## Status: Beta
Last updated 4 years ago by posva .
MIT · Original npm · Tarball · package.json
$ npm install vue-router 
SYNC missed versions from official npm registry.

vue-router-next CircleCI

Status: Beta

Know issues

Breaking changes compared to vue-router@3.x

  • The mode: 'history' option has been replaced with a more flexible one named history:

    import { createRouter, createWebHistory } from 'vue-router'
    // there is also createWebHashHistory and createMemoryHistory
    
    createRouter({
      history: createWebHistory(),
      routes: [],
    })
    
  • base option is now passed as the first argument to createWebHistory (and other histories)

  • Catch all routes (/*) must now be defined using a parameter with a custom regex: /:catchAll(.*)

  • router.match and router.resolve are merged together into router.resolve with a slightly different signature. Check its typing through autocomplete or Router's resolve method

  • router.getMatchedComponents is now removed as they can be retrieved from router.currentRoute.value.matched:

    router.currentRoute.value.matched.flatMap(record =>
      Object.values(record.components)
    )
    
    • The append argument has been removed. You can manually concatenate the value to an existing path instead.
  • RouterLink

    • append prop has been removed as well. Use the same workaround as above.
    • event prop has been removed. Use the v-slot API instead. See RFC.
    • tag prop has been removed. Use the v-slot API instead. See RFC.
    • exact prop has been removed. The caveat it was fixing is no longer present. See RFC.
  • If you use a transition, you may need to wait for the router to be ready before mounting the app:

    app.use(router)
    // Note: on Server Side, you need to manually push the initial location
    router.isReady().then(() => app.mount('#app'))
    

    Otherwise there will be an initial transition as if you provided the appear prop to transition because the router displays its initial location (nothing) and then displays the first location. This happens because navigations are all asynchronous now. If you have navigation guards upon the initial navigation, you might not want to block the app render until they are resolved.

  • On SSR, you need to manually pass the appropriate history:

    // router.js
    let history = isServer ? createMemoryHistory() : createWebHistory()
    let router = createRouter({ routes, history })
    // somewhere in your server-entry.js
    router.push(req.url) // request url
    router.isReady().then(() => {
      // resolve the request
    })
    
  • The object returned in scrollBehavior is now similar to ScrollToOptions: x is renamed to left and y is renamed to top. See RFC.

  • transition and keep-alive must now be used inside of RouterView via the v-slot API:

    <router-view v-slot="{ Component }">
      <transition>
        <keep-alive>
          <component :is="Component" />
        </keep-alive>
      </transition>
    </router-view>
    

    See more on the KeepAlive and the Transition examples. See RFC.

  • parent is removed from Route locations (this.$route and object returned by router.resolve). You can still access it via the matched array:

    const parent = this.$route.matched[this.$route.matched.length - 2]
    

Typings

To make typings more consistent and expressive, some types have been renamed. Keep in mind these can change until stable release to ensure consistency. Some type properties might have changed as well.

vue-router@3 vue-router@4
RouteConfig RouteRecordRaw
Location RouteLocation
Route RouteLocationNormalized

Improvements

These are technically breaking changes but they fix an inconsistent behavior.

  • Pushing or resolving a non existent named route throws an error instead of navigating to / and displaying nothing.
  • resolving(router.resolve) or pushing (router.push) a location with missing params no longer warns and produces an invalid URL (/), but explicitly throws an Error instead.
  • Empty children path does not append a trailing slash (/) anymore to make it consistent across all routes:
    • By default no route has a trailing slash but also works with a trailing slash
    • Adding strict: true to a route record or to the router options (alongside routes) will disallow an optional trailing slash
    • Combining strict: true with a trailing slash in your routes allows you to enforce a trailing slash in your routes. In the case of nested routes, make sure to add the trailing slash to the parent and not the empty child:
      let routes = [
        {
          path: '/parent/',
          children: [{ path: '' }, { path: 'child1/' }, { path: 'child2/' }],
        },
      ]
      
    • To redirect the user to trailing slash routes (or the opposite), you can setup a beforeEach navigation guard that ensures the presence of a trailing slash:
      router.beforeEach((to, from, next) => {
        if (to.path.endsWith('/')) next()
        else next({ path: to.path + '/', query: to.query, hash: to.hash })
      })
      
  • Because of the change above, relative children path redirect on an empty path are not supported anymore. Use named routes instead:
    // replace
    let routes = [
      {
        path: '/parent',
        children: [
          // this would now redirect to `/home` instead of `/parent/home`
          { path: '', redirect: 'home' },
          { path: 'home' },
        ],
      },
    ]
    // with
    let routes = [
      {
        path: '/parent',
        children: [
          { path: '', redirect: { name: 'home' } },
          { path: 'home', name: 'home' },
        ],
      },
    ]
    
    Note this will work if path was /parent/ as the relative location home to /parent/ is indeed /parent/home but the relative location of home to /parent is /home
  • Encoding is now more consistent. The initial navigation should yield the same results are in-app navigations.
    • Values in path, fullPath are not decoded anymore. They will appear as provided by the browser (most browsers provide them encoded).
    • params, query and hash are now all decoded
    • When using push, resolve and replace and providing a string location or a path property in an object, it must be encoded. params, query and hash must be provided in its decoded version.

Contributing

See Contributing Guide.

Current Tags

  • 4.4.0-alpha.3                                ...           edge (5 months ago)
  • 4.4.5                                ...           latest (2 months ago)
  • 3.6.5                                ...           legacy (2 years ago)
  • 4.0.13                                ...           next (3 years ago)

185 Versions

  • 4.4.5                                ...           2 months ago
  • 4.4.4                                ...           2 months ago
  • 4.4.3                                ...           3 months ago
  • 4.4.2                                ...           3 months ago
  • 4.4.1                                ...           3 months ago
  • 4.4.0                                ...           5 months ago
  • 4.4.0-alpha.3                                ...           5 months ago
  • 4.4.0-alpha.2                                ...           5 months ago
  • 4.4.0-alpha.1                                ...           5 months ago
  • 4.4.0-alpha.0                                ...           5 months ago
  • 4.3.3                                ...           5 months ago
  • 4.3.2                                ...           7 months ago
  • 4.3.1                                ...           7 months ago
  • 4.3.0                                ...           9 months ago
  • 4.3.0-alpha.1                                ...           10 months ago
  • 4.3.0-alpha.0                                ...           10 months ago
  • 4.2.5                                ...           a year ago
  • 4.2.4                                ...           a year ago
  • 4.2.3                                ...           a year ago
  • 4.2.2                                ...           a year ago
  • 4.2.1                                ...           a year ago
  • 4.2.0                                ...           2 years ago
  • 4.1.6                                ...           2 years ago
  • 3.6.5                                ...           2 years ago
  • 4.1.5                                ...           2 years ago
  • 3.6.4                                ...           2 years ago
  • 3.6.3                                ...           2 years ago
  • 3.6.2                                ...           2 years ago
  • 3.6.1                                ...           2 years ago
  • 4.1.4                                ...           2 years ago
  • 3.6.0                                ...           2 years ago
  • 4.1.3                                ...           2 years ago
  • 4.1.2                                ...           2 years ago
  • 4.1.1                                ...           2 years ago
  • 4.1.0                                ...           2 years ago
  • 4.1.0-beta.2                                ...           2 years ago
  • 4.1.0-beta.1                                ...           2 years ago
  • 4.1.0-beta.0                                ...           2 years ago
  • 4.1.0-51021cc                                ...           2 years ago
  • 4.1.0-730eb15                                ...           2 years ago
  • 4.1.0-9e62c00                                ...           2 years ago
  • 4.0.16                                ...           2 years ago
  • 3.5.4                                ...           2 years ago
  • 4.1.0-4da5e55                                ...           2 years ago
  • 4.1.0-c113369                                ...           2 years ago
  • 4.1.0-aabe509                                ...           3 years ago
  • 4.0.15                                ...           3 years ago
  • 4.0.14                                ...           3 years ago
  • 4.0.13                                ...           3 years ago
  • 3.5.3                                ...           3 years ago
  • 4.0.0-329e962                                ...           3 years ago
  • 4.0.12                                ...           3 years ago
  • 4.0.11                                ...           3 years ago
  • 4.0.10                                ...           3 years ago
  • 3.5.2                                ...           3 years ago
  • 4.0.9                                ...           3 years ago
  • 4.0.8                                ...           4 years ago
  • 4.0.7                                ...           4 years ago
  • 4.0.6                                ...           4 years ago
  • 4.0.5                                ...           4 years ago
  • 4.0.4                                ...           4 years ago
  • 3.5.1                                ...           4 years ago
  • 3.5.0                                ...           4 years ago
  • 4.0.3                                ...           4 years ago
  • 4.0.2                                ...           4 years ago
  • 4.0.1                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 4.0.0-rc.6                                ...           4 years ago
  • 4.0.0-rc.5                                ...           4 years ago
  • 4.0.0-rc.4                                ...           4 years ago
  • 4.0.0-rc.3                                ...           4 years ago
  • 3.4.9                                ...           4 years ago
  • 4.0.0-rc.2                                ...           4 years ago
  • 3.4.8                                ...           4 years ago
  • 4.0.0-rc.1                                ...           4 years ago
  • 3.4.7                                ...           4 years ago
  • 3.4.6                                ...           4 years ago
  • 4.0.0-beta.13                                ...           4 years ago
  • 3.4.5                                ...           4 years ago
  • 4.0.0-beta.12                                ...           4 years ago
  • 3.4.4                                ...           4 years ago
  • 4.0.0-beta.11                                ...           4 years ago
  • 4.0.0-beta.10                                ...           4 years ago
  • 4.0.0-beta.9                                ...           4 years ago
  • 4.0.0-beta.8                                ...           4 years ago
  • 4.0.0-beta.7                                ...           4 years ago
  • 3.4.3                                ...           4 years ago
  • 3.4.2                                ...           4 years ago
  • 3.4.1                                ...           4 years ago
  • 3.4.0                                ...           4 years ago
  • 4.0.0-beta.6                                ...           4 years ago
  • 4.0.0-beta.5                                ...           4 years ago
  • 4.0.0-beta.4                                ...           4 years ago
  • 4.0.0-beta.3                                ...           4 years ago
  • 4.0.0-beta.2                                ...           4 years ago
  • 4.0.0-beta.1                                ...           4 years ago
  • 4.0.0-alpha.14                                ...           4 years ago
  • 4.0.0-alpha.13                                ...           4 years ago
  • 3.3.4                                ...           4 years ago
  • 3.3.3                                ...           4 years ago
  • 3.3.2                                ...           4 years ago
  • 3.3.1                                ...           4 years ago
  • 3.3.0                                ...           4 years ago
  • 4.0.0-alpha.12                                ...           4 years ago
  • 3.2.0                                ...           4 years ago
  • 4.0.0-alpha.11                                ...           5 years ago
  • 4.0.0-alpha.10                                ...           5 years ago
  • 4.0.0-alpha.9                                ...           5 years ago
  • 4.0.0-alpha.8                                ...           5 years ago
  • 4.0.0-alpha.7                                ...           5 years ago
  • 4.0.0-alpha.6                                ...           5 years ago
  • 4.0.0-alpha.5                                ...           5 years ago
  • 4.0.0-alpha.4                                ...           5 years ago
  • 4.0.0-alpha.3                                ...           5 years ago
  • 4.0.0-alpha.2                                ...           5 years ago
  • 4.0.0-alpha.1                                ...           5 years ago
  • 3.1.6                                ...           5 years ago
  • 4.0.0-alpha.0                                ...           5 years ago
  • 3.1.5                                ...           5 years ago
  • 3.1.4                                ...           5 years ago
  • 3.1.3                                ...           5 years ago
  • 3.1.2                                ...           5 years ago
  • 3.1.1                                ...           5 years ago
  • 3.1.0                                ...           5 years ago
  • 3.0.7                                ...           5 years ago
  • 3.0.6                                ...           6 years ago
  • 3.0.5                                ...           6 years ago
  • 3.0.4                                ...           6 years ago
  • 3.0.3                                ...           6 years ago
  • 3.0.2                                ...           6 years ago
  • 3.0.1                                ...           7 years ago
  • 2.8.1                                ...           7 years ago
  • 3.0.0                                ...           7 years ago
  • 2.8.0                                ...           7 years ago
  • 2.7.0                                ...           7 years ago
  • 2.6.0                                ...           7 years ago
  • 2.5.3                                ...           8 years ago
  • 2.5.2                                ...           8 years ago
  • 2.5.1                                ...           8 years ago
  • 2.5.0                                ...           8 years ago
  • 2.4.0                                ...           8 years ago
  • 2.3.1                                ...           8 years ago
  • 2.3.0                                ...           8 years ago
  • 2.2.1                                ...           8 years ago
  • 2.2.0                                ...           8 years ago
  • 2.1.3                                ...           8 years ago
  • 2.1.2                                ...           8 years ago
  • 2.1.1                                ...           8 years ago
  • 2.1.0                                ...           8 years ago
  • 2.0.3                                ...           8 years ago
  • 2.0.2                                ...           8 years ago
  • 2.0.1                                ...           8 years ago
  • 2.0.0                                ...           8 years ago
  • 2.0.0-rc.7                                ...           8 years ago
  • 2.0.0-rc.6                                ...           8 years ago
  • 2.0.0-rc.5                                ...           8 years ago
  • 2.0.0-rc.4                                ...           8 years ago
  • 2.0.0-rc.3                                ...           8 years ago
  • 2.0.0-rc.2                                ...           8 years ago
  • 2.0.0-rc.1                                ...           8 years ago
  • 2.0.0-beta.4                                ...           8 years ago
  • 2.0.0-beta.3                                ...           8 years ago
  • 2.0.0-beta.2                                ...           8 years ago
  • 2.0.0-beta.1                                ...           8 years ago
  • 0.7.13                                ...           9 years ago
  • 0.7.12                                ...           9 years ago
  • 0.7.11                                ...           9 years ago
  • 0.7.10                                ...           9 years ago
  • 0.7.9                                ...           9 years ago
  • 0.7.8                                ...           9 years ago
  • 0.7.7                                ...           9 years ago
  • 0.7.6                                ...           9 years ago
  • 0.7.5                                ...           9 years ago
  • 0.7.4                                ...           9 years ago
  • 0.7.3                                ...           9 years ago
  • 0.7.2                                ...           9 years ago
  • 0.7.1                                ...           9 years ago
  • 0.7.0                                ...           9 years ago
  • 0.6.2                                ...           9 years ago
  • 0.6.1                                ...           9 years ago
  • 0.6.0                                ...           9 years ago
  • 0.5.2                                ...           9 years ago
  • 0.5.1                                ...           9 years ago
  • 0.5.0                                ...           9 years ago
  • 0.4.0                                ...           9 years ago
Maintainers (2)
Downloads
Total 2
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (47)

© 2010 - cnpmjs.org x YWFE | Home | YWFE