🎈 perf: 优化路由

This commit is contained in:
Litrix2 2024-12-22 21:38:48 +08:00
parent 14e2e3758b
commit a469e3c86d
4 changed files with 16 additions and 10 deletions

View File

@ -22,18 +22,21 @@ const routes: RouteRecordRaw[] = [
name: 'User',
component: () => import('@/views/user/UserPage.vue'),
redirect: ({ params: { id } }) => ({
name: useUserStore().isSelf(id as string) ? 'UserEdit' : 'UserPosts',
name: useUserStore().isSelf(id as string) ? 'UserEdit' : 'UserPost',
}),
children: [
{
path: 'posts',
name: 'UserPosts',
component: () => import('@/views/user/UserPosts.vue'),
path: 'post',
name: 'UserPost',
component: () => import('@/views/user/UserPostPage.vue'),
},
{
path: 'edit',
name: 'UserEdit',
component: () => import('@/views/user/UserEditPage.vue'),
meta: {
shouldLogin: true,
},
},
],
},

View File

@ -1,9 +1,12 @@
<template>
<el-main class="error-page !flex flex-col justify-center items-center">
<div class="error-page__reason">{{ descriptionMap[type] }}</div>
<router-link custom v-slot="{ navigate }" to="/">
<el-button type="primary" @click="navigate">返回首页</el-button>
</router-link>
<div class="flex">
<router-link custom v-slot="{ navigate }" to="/">
<el-button type="primary" @click="$router.back()">返回上页</el-button>
<el-button type="primary" @click="navigate">返回首页</el-button>
</router-link>
</div>
</el-main>
</template>

View File

@ -41,7 +41,7 @@
<el-menu class="menu" router :default-active="$route.fullPath">
<h4 class="mb-5px text-center">个人中心</h4>
<el-divider />
<el-menu-item :index="`/user/${$route.params.id}/posts`">发帖记录</el-menu-item>
<el-menu-item :index="`/user/${$route.params.id}/post`">发帖记录</el-menu-item>
<template v-if="userStore.isSelf(userInfo.id)">
<el-divider />
<el-menu-item :index="`/user/${$route.params.id}/edit`">编辑信息</el-menu-item>
@ -55,9 +55,9 @@
</template>
<template v-else>
<div class="font-bold text-30px">无法获取用户信息</div>
<div class="flex gap-10px">
<el-button type="primary" @click="loadUserInfo">刷新</el-button>
<div class="flex">
<el-button type="primary" @click="$router.back()">返回上页</el-button>
<el-button type="primary" @click="loadUserInfo">刷新</el-button>
</div>
</template>
</div>