Как мне перенаправить на вход в систему, если путь «/» или «/ логин»? - PullRequest
2 голосов
/ 14 октября 2019

Как мне перенаправить, если путь «/» или «/ логин». Я думал о добавлении другого объекта с '/', и компонент все равно будет входить в систему, но я не знаю, правильно ли это. Вот мой роутер.

const router = new Router({
    mode: 'history',
    linkExactActiveClass: 'active',
    routes: [
        {
            name: 'dashboard',
            path: '/dashboard',
            component: Dashboard,
            meta: {
                requiresAuth: true
            }
        },
        {
            name: 'profile',
            path: '/profile',
            component: Profile,
            meta: {
                requiresAuth: true
            }
        },
        {
            name: 'login',
            path: '/login',
            component: Login,
            meta: {
                requiresVisitor: true
            }
        },
        {
            name: 'logout',
            path: '/logout',
            component: Logout,
            meta: {
                requiresAuth: true
            }
        }
    ]
});

1 Ответ

2 голосов
/ 14 октября 2019

если вы хотите перенаправить с помощью '/' или '/ login', так что вы можете попробовать это

const router = new Router({
    mode: 'history',
    linkExactActiveClass: 'active',
    routes: [
      {
        path: '',
        redirectTo: '/login',
        pathMatch: 'full'
      },
        {
            name: 'dashboard',
            path: '/dashboard',
            component: Dashboard,
            meta: {
                requiresAuth: true
            }
        },
        {
            name: 'profile',
            path: '/profile',
            component: Profile,
            meta: {
                requiresAuth: true
            }
        },
        {
            name: 'login',
            path: '/login',
            component: Login,
            meta: {
                requiresVisitor: true
            }
        },
        {
            name: 'logout',
            path: '/logout',
            component: Logout,
            meta: {
                requiresAuth: true
            }
        }
    ]
});
...