我想重定向用户单击注销链接到服务器呈现的注销页面。但是,由于它代表下面的代码,我只是重定向到默认路径。VueJS与vue-router如何重定向到服务器路由
我在烧瓶内的服务器的路由设置了如下所示:
@app.route('/logout')
def logout():
logout_user()
return render_template('login.html')
在VUE我想重定向路由,这样我直接到服务器的路由。
<template>
<a v-on:click="logout">Logout</a>
</template>
<script>
export default {
name: SomePage.vue
},
methods: {
logout() {
this.$router.replace('/logout')
// I also tried .go('/logout')
}
}
</script>
那么我需要在我的路由器中设置路由吗?
export default new Router {
routes: {
{
path: '/'
component: Default
children: [
{
path: '/logout'
// no component added here - is it needed?
}
]
}
}
正如我已经重定向到/注销,我不知道如何添加该路由的组成部分,将有助于我只想去碱/注销,并得到由服务器返回的网页的.html 。有任何想法吗?
请编辑这篇文章提供解释和/或关于该解决方案为什么会起作用的其他上下文。 – Toby
@Toby,根据Vue文档“为了与HTML5历史API保持一致,router.go现在仅用于后退/前进导航,而router.push则用于导航到特定页面。” https://vuejs.org/v2/guide/migration-vue-router.html希望这有帮助。 –