v2.2.0
New Features
-
Passing Props to Route Components
Instead of relying on the magic
$routeproperty, you can now use thepropsroute config option to inject route params into route components as props. -
New in-component hook:
beforeRouteUpdateThis new in-component hook is called when the route that renders this component has changed, but this component is reused in the new route.
For example, for a route with dynamic params
/foo/:id, when we navigate between/foo/1and/foo/2, the sameFoocomponent instance will be reused, and this hook will be called when that happens. Previously you will have to setup a watcher on$routeto achieve the same.This hook has access to
thiscomponent instance. -
New router instance method:
router.onReadyThis method queues a callback to be called when the router has completed the initial navigation, which means it has resolved all async enter hooks and async components that are associated with the initial route.
This is useful in server-side rendering to ensure consistent output on both the server and the client.
-
New router instance method:
router.addRoutesDynamically add more routes to the router. The argument must be an Array using the same route config format with the
routesconstructor option. -
Callbacks for
router.push()androuter.replace()You can now optionally provide
onCompleteandonAbortcallbacks torouter.pushorrouter.replaceas the 2nd and 3rd arguments. These callbacks will be called when the navigation either successfully completed (after all async hooks are resolved), or aborted (navigated to the same route, or to a different route before current navigation has finished), respectively. -
Shared Router Instance for Multiple Root Components
Thanks to the contribution by @jhartman86 via #1108!
It is now supported to use the same router instance to drive multiple root components on the same page.
Changes
-
router.resolvereturn value changed to:{ location: Location; route: Route; href: string; }
The old
resolvedandnormalizedTofields are deprecated, but preserved for backwards compatibility. -
URL query encoding now better conforms to RFC3986:
- now encodes
!'()*. - no longer encodes
,.
- now encodes