Vue挖坑指南:[vue-router] Named Route 'XXX' has a default child route.
阿新 • • 發佈:2018-11-10
前言
OA系統,使用了路由的巢狀,希望在訪問子模組時,預設載入模組的預設路由。即為子模組設定預設路由 。
開始
我們先來看看,如何為子模組設定預設的路由。
這樣寫,會出現什麼問題呢?開啟控制檯看看。
實踐
vue-router給我們報了兩個警告,我們一個一個來看。
第一個:[vue-router] Named Route 'companyStructure' has a default child route. When navigating to this named route (:to="{name: 'companyStructure'"), the default child route will not be rendered. Remove the name from this route and use the name of the default child route for named links instead.
這是因為我們為一級路由設定了預設的子路由,實際是訪問了設定的子路由,所以把一級路由的name屬性去掉即可。
第二個:[vue-router] Duplicate named routes definition: { name: "index", path: "/companyStructure/" }.
name要保證唯一性。我們可以保持一級路由的name屬性,將二級路由的name值修改成唯一的即可。
總結
2018/11/01又是新的一個月開始,感覺2018年就快要過完咯~大家有什麼新年計劃呢?一起分享啊
歡迎留言指導,感謝~或者掃描下方二維碼,與我取得聯絡~ (記得備註:CSND喔~)