使用extendRoutesnuxt 路由器的屬性,我試圖區分以斜杠結尾的路徑和不以斜杠結尾的路徑。這是由于我們使用的 CMS 處理路徑的方式。
我可以/all通過將概覽頁面區分為以or結尾的路徑來區分它們/overview,但這并不理想。
_slug.vue我的頁面目錄上有一個
(應該匹配/articles/some-article-1)
我有一個嵌套類別的文章概述路線。
(應該匹配/articles/ /articles/category/和/articles/category/category-of-category/)
這似乎有效,
routes.unshift({
name: 'articles',
path: '/articles/:category([^/]*/)',
component: resolve(__dirname, 'pages/-overview.vue')
})
但引發錯誤:
預期“類別”與“[^/]*/”匹配,但收到“dfdf/”
如何正確匹配以斜杠結尾的路徑?
uj5u.com熱心網友回復:
你試過這個嗎?
const router = createRouter({
history: createWebHistory(),
routes: [
{
name: 'articles',
path: '/articles/:category',
strict: true,
component: resolve(__dirname, 'pages/-overview.vue')
},
...
]
})
// or, for all routes
const router = createRouter({
history: createWebHistory(),
routes: [
...
],
strict: true
})
https://router.vuejs.org/guide/essentials/route-matching-syntax.html#sensitive-and-strict-route-options
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/478083.html
