構(gòu)建選項區(qū)別
vue2-router
const router-new VueRouter({
mode:history,
base:_name,
})
vue-next-router
import { createRouter,createWebHistory} from vue-next-router
const router=createRouter({
history:createHistory(/)
})
在上述代碼中我們發(fā)現(xiàn),vue2中的構(gòu)建選項mode和base,分別為mode和base,而在vue-next-router中變成了,history和history中的第一個參數(shù)/.
捕獲路由加正則表達式/:catchAll(.*)
vue2-router
const router=new VueRouter({
mode:history,
routes:[
{path:/user/:a*}
]
})
vue-next-router
const router=createRouter({
history:createWebHistrory(),
routes:[
{path:/user/:a:catchAll(.*).component:component}
]
})
當(dāng)路由為 /user/a/b 時,捕獲到的 params 為 {“a”: “a”, “catchAll”: “/b”}。
match改變(vue2/3)
match詳解點擊這里
router.match和router.resolve在vue3中已經(jīng)被合并,只是簽名略有不同。
刪除router.getMatchedComponents,可以從router.currentRoute.value.matched 中獲取。
router.getMatchedComponents 返回目標(biāo)位置或是當(dāng)前路由匹配的組件數(shù)組 (是數(shù)組的定義/構(gòu)造類,不是實例)。通常在服務(wù)端渲染的數(shù)據(jù)預(yù)加載時使用。文章來源:http://www.zghlxwxcb.cn/news/detail-664149.html
push 或者 resolve 一個不存在的命名路由時,將會引發(fā)錯誤,而不是導(dǎo)航到根路由 “/” 并且不顯示任何內(nèi)容。
在vue2中會自動跳轉(zhuǎn)到跟路由/中,而vue3會報錯。文章來源地址http://www.zghlxwxcb.cn/news/detail-664149.html
到了這里,關(guān)于vue-router在vue2/3區(qū)別的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!