Vue.js 路由器不顯示正確的子路由
我遇到了 Vue.js 路由器的問題。正如標題所示,這個問題是關于只顯示父路由頁面的子路由。例如,您的帳戶詳細信息有一個路徑www.example.com/account。然后,在您的帳戶,你可以看到不同的項目,這將是可用的路線www.example.com/account/project/foobar那里project/foobar是一個孩子的路線/account和foobar是一個動態參數?,F在,當您進入一個項目時,您希望看到該項目,但您仍然會看到帳戶頁面。這是我遇到的問題。我覺得一切都設置正確,但代碼無論如何都顯示在下面。路由器.jsconst routes = [ ..., // other routes { path: '/account', component: AccountPage, meta: { title: 'Your account' }, children: [ { path: 'project/:id', component: ProjectPage, props: true, meta: { title: 'Project' } } ] }];const router = new VueRouter({ routes, mode: 'history'});// Sets meta tags in the HEAD tag to, for example, change the title.router.beforeEach((to, from, next) => { const nearestWithTitle = to.matched.slice().reverse().find(r => r.meta && r.meta.title); const nearestWithMeta = to.matched.slice().reverse().find(r => r.meta && r.meta.metaTags); const previousNearestWithMeta = from.matched.slice().reverse().find(r => r.meta && r.meta.metaTags); if(nearestWithTitle) document.title = nearestWithTitle.meta.title; Array.from(document.querySelectorAll('[data-vue-router-controlled]')).map(el => el.parentNode.removeChild(el)); if(!nearestWithMeta) return next(); }); }) .forEach(tag => document.head.appendChild(tag)); next();});我四倍檢查了我是否使用了正確的組件,并且我 100% 確定我這樣做了。不過,它只是一直顯示帳戶頁面而不是項目頁面。我確實注意到標題因更改元標記的代碼而發生了變化,這意味著它知道下一頁是項目頁面。我還檢查了函數參數to包含的內容,并很快發現這是它想要去的項目路線,這完全有道理。項目頁面.vue<template> <transition name="project-anim"> <div> Foo BAR </div>< /transition></template><script> import MeineProject from '../../components/meine/project'; export default { components: { MeineProject } }</script>直接轉到 URL(沒有通過鏈接或任何東西進行路由導航),也只顯示帳戶頁面,所以我很確定這不是由于某種原因無法正常工作的轉換??刂婆_中沒有錯誤或警告。我完全沒有選擇。我希望你能幫助我。謝謝你的時間!:)
查看完整描述