我正在制作一个带有重定向功能的登录页面,逻辑如下:
如果我从未登录并输入 url '/home/qiputranscode',它将重定向到
' http://127.0.0.1:8000/#/login?redirect=%2Fhome%2Fqiputranscode '。
然后我需要使用用户名和密码请求服务器以获取进入“/home/qiputranscode”页面的令牌。
但是在输入我的用户名和密码后,网址变为:
' http://127.0.0.1:8000/?#/login?redirect=%2Fhome%2Fqiputranscode '
并且没有请求服务器或重定向到“/home/qiputranscode”。
那么,为什么要添加 url 呢?在#之前本身。
它们之间有什么区别,如果你给我任何建议,我将不胜感激
重定向代码如下:
router.beforeEach((to, from, next) => {
if (to.matched.some(r => r.meta.requiredAuth)) {
if (store.state.token) {
next()
} else {
next ({
path: '/login',
query: {redirect: to.fullPath}
})
}
} else {
next()
}
});
后面的部分?
是query
withkey=redirect
和value=full path
要重定向到保存的路径,请在登录后调用它
this.$router.push({ path: this.$route.query.redirectTo })
而且您还需要防止默认表单行为
<form v-on:submit.prevent ...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句