javascript - 带后退按钮的 Vue.js 路由

标签 javascript vue.js vue-router

我已经使用了这个 Vue.js 路由示例应用程序。

https://github.com/chrisvfritz/vue-2.0-simple-routing-example

src/main.js 我有这么多数据值(value)。

const app = new Vue({
  el: '#app',
  data: {
    currentRoute: window.location.pathname,
    token : "",
    errorMessage : '', etc...etc..
  },

现在使用 socket.io,我将 token 设置为 "sdawdda2d2ada2ad22ad"

当应用程序启动时,currentRoute 等于 "/" 没问题,第一页已加载。 src/routes.js

'/': 'Home',
'/about': 'About'

当我想检查/about (url: localhost:8080/about) 时,效果很好,但 token 和错误消息再次为空,因为应用程序再次创建。

如果我想在不丢失 token 值的情况下更改页面,我可以使用:

this.currentRoute = "/about"       (url: localhost:8080)

它运行良好,但 url 没有改变,所以我不能在浏览器中使用后退按钮。 如果我不想在浏览器转到/about 时丢失 token 值,我该如何分离我的 Vue 应用程序?

非常感谢!

最佳答案

你可以做类似this.$router.go(-1)vm.$router.go(-1) 的事情来继续this .$router.go(1) 更多click here

关于javascript - 带后退按钮的 Vue.js 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40182536/

相关文章:

vue.js - 如何在 nuxt.js 中编写全局路由函数

node.js - Express 抛出 404 url​​ 中是否有点 - Vue、webpack

javascript - 如何防止稍后更改复选框值?

javascript - 如何打破一系列字符串replace()?

jquery - 在 vuejs 中使用 jQuery 数据表

javascript - 数组/列表长度为零但数组不为空

javascript - 类型 'this' 不可分配给类型 'T'

javascript - 没有显示输出

angular - vue 中的 component 与 angular 的等价物是什么?

javascript - 页面历史记录的暂停功能 向前 向后