我的問題有一下幾點
1. router-view 在使用name進行命名
這個命名,我再三確定沒有命名錯誤的情況下。我的組件死活出不來。仔細排查了之后,也反復看了官方文檔。終于發現
<router-view name="login"></router-view>
這個是路由上的實現方式為:
{path: '/login',name: 'login',components: {login: Login},//component: Login,// 添加元信息,可用于全局前置守衛判斷是否需要鑒權meta: {requiresAuth: false, // 登錄頁面不需要鑒權},},
一定一定不能是這種,會識別不上的!!!!
{path: '/login',name: 'login',component:Login,//component: Login,// 添加元信息,可用于全局前置守衛判斷是否需要鑒權meta: {requiresAuth: false, // 登錄頁面不需要鑒權},},
而且默認路由為第一個components下面的第一個,其他的就可以通過router-view 中的那么調用!!!!
2.router-link 使用 :to="{name=‘xxxx’}"時的問題
一定要明白這玩意是跳轉,他與router-view有著本質上的不同。而且跳轉的路由下的組件,一定得在當前頁面才可以!!!
比如:這樣就不行
<li><router-link active-class="active" :to="{name:'login'} " replace>Login</router-link>
</li>
這樣就可以
<li><router-link active-class="active" :to="{name:'login'} " replace>Login</router-link>
</li><router-view name="login"></router-view>