v2.1.0
Dist File Change
The main
for the NPM package is now vue-router.common.js
. This requires no change for existing build setups. The only difference is that the CDN link for the browser-build is now https://unpkg.com/[email protected]/dist/vue-router.js.
New
-
New method:
router.resolve()
(@hogart via #918). The user can use this method to get a resolved route object or href string. The signature for this method is:resolve (to: RawLocation, current?: Route, append?: boolean): { normalizedTo: Location; resolved: Route; href: string; }
-
router.getMatchedComponents()
can now resolve and determine the matched components for the location passed to it as argument. Note during server-side rendering, you will still need to explicitlyrouter.push()
the url so that the$route
object is available to data preFetch functions. -
router.push()
androuter.replace()
can now accept a location object with just params:router.push({ params: { foo: 'bar' }})
Note this will do nothing if the current active route doesn't have the matching params; it is your responsibility to ensure this only gets called on appropriate routes.
-
router.push()
androuter.replace()
now also acceptappend: true
in the location object:// will navigate to /foo/bar from /foo router.push({ path: 'bar', append: true })
-
When using
next
in route navigation for a redirect, guards now acceptreplace: true
in the location object:router.beforeEach((to, from, next) => { if (to.path === '/foo') { next({ path: '/bar', replace: true }) } })
-
New prop
event
for<router-link>
, allows defining the events to trigger a navigation. Can be a string or an Array of strings.