Migration (vue-router v5.3.1)
v4 → v5
Full guide: https://router.vuejs.org/guide/migration/v4-to-v5.html
- Install
vue-router@5; dropunplugin-vue-routerif present. The plugin moved into the core package (package.json:104-114):unplugin-vue-router/vite→vue-router/vite- other bundlers →
vue-router/unplugin/{webpack,rollup,esbuild,rolldown} - utilities (
VueRouterAutoImports,EditableTreeNode,createRoutesContext, ...) →vue-router/unplugin - Volar plugins →
vue-router/volar/sfc-typed-router,vue-router/volar/sfc-route-blocks
- Virtual module
virtual:generated-pages→vue-router/auto-routes. - Data loaders moved from
unplugin-vue-router/data-loaderstovue-router/experimental; Pinia Colada loader tovue-router/experimental/pinia-colada. - IIFE build no longer bundles
@vue/devtools-apiv8 (no IIFE exists for it); affects CDN/script-tag setups (https://github.com/vuejs/router/releases/tag/v5.0.0). - Query params in typed routes are optional by default.
v3 → v4 (still relevant when porting old apps)
Full guide: https://router.vuejs.org/guide/migration/v3-to-v4.html (release notes: https://github.com/vuejs/router/releases/tag/v4.0.0)
new VueRouter()→createRouter({...}); history is explicit:createWebHistory/createWebHashHistory/createMemoryHistory;mode: 'history'is gone.- Catch-all changed:
path: '*'→path: '/:pathMatch(.*)*'. router.onReady()removed →router.isReady()returns a Promise.router.appremoved → pass the app where needed.scrollBehaviorreturns{ left, top }(was{ x, y }).router.currentRouteis a ref: userouter.currentRoute.value.nextin guards became optional; v5.0.3 added a runtime deprecation warning for it — return a value instead.- Dynamic route matching (
addRoute/removeRoute) replacedaddRoutes.
Deprecations active in v5.3.1
| Deprecated | Replacement | Evidence |
|---|---|---|
vue-router/auto |
vue-router/auto-routes (+ vue-router/auto-resolver) |
vue-router-auto.d.ts:1 |
new NavigationResult(to) in loaders |
reroute(to) |
dist/experimental/index.js:1106-1111 |
next() callback in guards |
return values | dist/index-D7ja2BKs.d.ts:362-393 |
selectNavigationResult (experimental) |
removed in v5.0.3 | https://github.com/vuejs/router/releases/tag/v5.0.3 |
In-line changes worth knowing (5.0.3 → 5.3.1)
Cited by release URL; do not trust file copies of changelogs.
- 5.0.3 —
miss()returnsnever;reroute()added;_parentfolder convention;next()deprecation warning. https://github.com/vuejs/router/releases/tag/v5.0.3 - 5.0.5 — Standard Schema validators usable as param parsers. https://github.com/vuejs/router/releases/tag/v5.0.5
- 5.0.7 —
RouteNamedMapwired through the generated dts (PR #2700);params: {}hint in discarded-params warning; query object usesObject.create(null)(prototype pollution fix). https://github.com/vuejs/router/releases/tag/v5.0.7 - 5.1.0 —
defineParamParserRaw; typeddefinePagepath params; strict default typing;TypesConfigRouteroverride; experimental export is ESM-only. https://github.com/vuejs/router/releases/tag/v5.1.0 - 5.2.0 — diagnostics for common mistakes; pinia 4 allowed. https://github.com/vuejs/router/releases/tag/v5.2.0
- 5.3.0 — scroll skipped per
history.scrollRestoration; duplicatedefinePage()reported;EditableTreeNode.nameunsettable→false. https://github.com/vuejs/router/releases/tag/v5.3.0 - 5.3.1 —
isActivefixed for non-string params. https://github.com/vuejs/router/releases/tag/v5.3.1