Vue Routes 4. x
Vue Router 官网: https://router.vuejs.org/zh/
变化: https://router.vuejs.org/zh/guide/migration/
new Router 变成 createRouter
js
// 以前是
// import Router from 'vue-router'
import { createRouter } from 'vue-router'
const router = createRouter({
// ...
})新的 history 配置取代 mode
mode: 'history' 配置已经被一个更灵活的 history 配置所取代
"history":createWebHistory()"hash":createWebHashHistory()"abstract":createMemoryHistory()
删除了通配符路由
使用 regex 参数
js
const routes = [
{ path: '/:pathMatch(.*)*', name: 'not-found', component: NotFound }
]主动跳转 404
js
router.push('/not/found')
// 或者
router.push({
name: 'not-found',
params: { pathMatch: ['not', 'found'] }
})