You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bloggingplatform/Frontend/src/router/index.ts

125 lines
3.2 KiB

import { createRouter, createWebHistory } from 'vue-router';
// 动态导入组件
const HomeView = () => import('../views/HomeView.vue');
const Post = () => import('@/views/posts/post.vue');
const Login = () => import('../views/RegisterLogin/Login.vue');
const Register = () => import('../views/RegisterLogin/Register.vue');
const ForgotPassword = () => import('../views/RegisterLogin/ForgotPassword.vue');
const ResetPassword = () => import('../views/RegisterLogin/ResetPassword.vue');
const AdminLogin = () => import('../views/RegisterLogin/AdminLogin.vue');
const AdminForgotPassword = () => import('../views/RegisterLogin/AdminForgotPassword.vue');
const AdminResetPassword = () => import('../views/RegisterLogin/AdminResetPassword.vue');
const LogoutDialog = () => import('../views/RegisterLogin/LogoutDialog.vue');
const AdminView = () => import('../views/AdminView.vue');
const ProfileView = () => import('../views/ProfileView.vue');
const ArticleView = () => import('../views/ArticleView.vue');
// 创建路由实例
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'Home',
component: HomeView,
},
{
path: '/post/:id', // 使用动态参数 :id
name: 'PostDetail',
component: Post,
props: true, // 将路由参数传递给组件
},
{
path: '/login',
name: 'Login',
component: Login,
},
{
path: '/register',
name: 'Register',
component: Register,
},
{
path: '/forgot-password',
name: 'ForgotPassword',
component: ForgotPassword,
},
{
path: '/reset-password',
name: 'ResetPassword',
component: ResetPassword,
},
{
path: '/Adminlogin',
name: 'AdminLogin',
component: AdminLogin,
},
{
path: '/Adminforgot-password',
name: 'AdminForgotPassword',
component: AdminForgotPassword,
},
{
path: '/Adminreset-password',
name: 'AdminResetPassword',
component: AdminResetPassword,
},
{
path: '/logout',
name: 'Logout',
component: LogoutDialog,
},
{
path: '/admin',
name: 'Admin',
component: AdminView,
children: [
{
path: '/profile',
name: 'AdminProfile',
component: ProfileView, // 保留作为管理员的子路由
},
{
path: '/article',
name: 'Article',
component: ArticleView,
},
]
},{
path: '/user',
name: 'User',
component: () => import('../views/UserView.vue'),
children: [
{
path: '/profile1',
name: 'Profile1',
component: () => import('../views/ProfileView1.vue'),
},
{
path: '/article1',
name: 'Article1',
component: () => import('../views/ArticleView.vue'),
},
{
path: '/edit',
name: 'Edit',
component: () => import('../views/edit.vue'),
},
{
path: '/display',
name: 'Display',
component: () => import('../views/display.vue'),
},
{
path: '/accounts',
name: 'accounts',
component: () => import('../views/accounts.vue'),
},
]
}
],
});
export default router;