1 回答

TA贡献1802条经验 获得超6个赞
处理此问题的一种方法是使用一个中间页面组件,该组件仅包含所需的布局,其他路由嵌套在其下方。
您的路线可能如下所示:
const router = new VueRouter({
mode: 'history',
routes: [
{
title: 'Login Page',
path: '/back/login',
name: 'login',
component : Login
},
{
path: '',
component: LoggedInLayout,
children: [
{
title: 'Dashboard',
path: '/',
name: 'dashboard',
component: Dashboard
},
{
path: '/post',
name: 'post',
component: Post
},
]
}
]
});
然后,您的已登录布局组件将包含当前在 MainApp 组件中的所有内容的元素
LoggedInLayout.vue
<template>
<div class="main-wrapper">
<div class="navbar-bg"></div>
<TopNav />
<SideBar />
<div class="main-content">
<router-view></router-view>
</div>
<Footer />
</div>
</template>
...而你的主应用组件实际上只是一个:router-view
MainApp.vue
<template>
<router-view></router-view>
</template>
请注意,路由文件中的条目具有一个空字符串作为路径。这意味着它不会向路线添加任何内容。帖子仍可在 访问。LoggedInLayoutyourapp.com/post
它也没有名称,因为您实际上并不想仅导航到已登录的布局。它总是在那里为其他页面服务。
添加回答
举报