I have already implemented a Vue.js Routing example application found on GitHub. You can check it out here:
https://github.com/chrisvfritz/vue-2.0-simple-routing-example
In my src/main.js
, I am managing a lot of data values.
const app = new Vue({
el: '#app',
data: {
currentRoute: window.location.pathname,
token : "",
errorMessage : '', and more...
},
Now, using socket.io, I set the token to "sdawdda2d2ada2ad22ad"
Upon starting the application, the current route is equal to "/"
, which means the first page gets loaded from src/routes.js
.
'/': 'Home',
'/about': 'About'
When navigating to /about
(url: localhost:8080/about
), everything works as expected, but the token and error message become empty because the app gets created again.
To change the page without losing the token value, I can use:
this.currentRoute = "/about" (url: localhost:8080)
This method works well, but the URL doesn't change, so I can't utilize the back button in the browser. How can I segregate my Vue app so that I don't lose the token value when navigating to /about
?