I already use this Vue.js Routing example application.
https://github.com/chrisvfritz/vue-2.0-simple-routing-example
In the src/main.js
I have so much data value .
const app = new Vue({
el: '#app',
data: {
currentRoute: window.location.pathname,
token : "",
errorMessage : '', etc...etc..
},
Now with socket.io i set the token to "sdawdda2d2ada2ad22ad"
When application start than the currentRoute is equal with "/"
Its okey, the first page loaded. src/routes.js
'/': 'Home',
'/about': 'About'
When i want to check the /about (url: localhost:8080/about
), than its works good , but the token and errorMessage is empty again, because the app created again.
If i want to change page without lose the token value i can use:
this.currentRoute = "/about" (url: localhost:8080)
Its works good , but the url not change, so i cant use back button in browser. How can i separate my Vue app, if i dont want to lose token value when the browser go to /about?
Thanks so much!
In Vue. js you can take advantage of the Vue Router methods. You can use router.go(n) method to programmatically navigate backwards or forwards. It takes an integer as the only parameter that tells the method how many steps to go forward or backwards.
Vue. js provides a bunch of features that allow you to build reusable web components. Routing is one of those methods. It allows the user to switch between pages without refreshing the page.
We can use router. beforeEach to listen for routing events globally across the application. This is worth using if you have authentication checks or other pieces of functionality that should be used in every route. Here's an example that simply logs out the route the user is going to and coming from.
simple way
<template lang="html">
<div>
<button @click="goBack">
Back
</button>
</div>
</template>
<script>
export default {
methods: {
goBack() {
this.$router.go(-1)
}
}
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With