Vue路由器无法正常工作,我找不到缺陷。
在IE 11上运行此应用程序很重要。 登录并刷新应用后,可以正确浏览内部。 由于使用了相同的方法,因此无法从登录重定向到仪表板或注销后。.
Vue,Vue路由器,Vuex
code is:
methods: {
onSubmit () {
....
this.$store.dispatch('AUTH_REQUEST', reqBody).then( () => {
this.$router.push('/dashboard')
)}
}
Chrome Mozilla IE11
this.$router.push('/dashboard') no no no
this.$router.replace('/dashboard') no no no
this.$router.go('/dashboard') yes yes no
<v-list-tile yes yes yes
to='/any_routes'
>
<router-link yes yes yes
to="/any_routes"
>Any routes here</router-link>
编辑 添加routes.js
const token = store.state.token
const ifAuthenticated = (to, from, next) => {
if (!token) {
next()
return
}
next('/app')
}
const ifNotAuthenticated = (to, from, next) => {
if (token) {
next()
return
}
next('/')
}
let appPages = {
path: '/app',
redirect: '/app/dashboard',
name: 'appLayout',
component: appLayout,
beforeEnter: ifNotAuthenticated,
children: [
{
path: 'dashboard',
name: 'Dashboard',
component: Dashboard ,
},
{
path: 'admin_users',
name: 'Admin Users',
component: AdminMenu
},
{
path: 'user_profile',
name: 'User Profile',
component: UserProfile
},
{
path: 'information',
name: 'Information',
component: InformationMenu,
children: [
{
path: 'test',
name: 'tets',
component: TestMenu
}
]
}
]
}
const routes = [
appPages,
{
path: '/',
redirect: '/login',
name: 'AuthLayout',
component: AuthLayout,
beforeEnter: ifAuthenticated,
children: [
{
path: 'login',
name: 'Login',
components: {default: Login}
}
]
},
{
path: '*',
name: 'Missing page',
component: MissingPage
}
]
export default routes
请提供想法如何解决此问题:)