Like #575 - I have 3 path
1. _/_ (name: root)
2. _/first_ (name: first)
3. _/first/second_ (name: second)
I do $route.push({name: first}); And next $route.push({name: second});
How can I go back? (click "close" for modal, or button "arrow back" like activity)
Ok. But if I paste or type URL before? _vue-router_ it may?
_vue-router_ has $route.back() like alias for $route.go(-1); This does not work if there is no history.
I need to do my own thing?.. But.. I do the following
{ path: '/', name: 'root', component: RootActivity, meta: {back: 'searchSettings'} },
{ path: '/first', name: 'first', component: FirstActivity, meta: {back: 'RootActivity'} },
{ path: '/second', name: 'second', component: SecondActivity, meta: {back: 'SecondActivity'} },
And in my click button "back method":
var {back} = this.$route.meta;
if(back) {
this.$router.replace({name: back});
} else {
// When no one knows where to go
this.$router.replace('/');
}
I think this is standard behavior. Used often. You could make the method "back" smarter like this (no use meta)
{ path: '/second', name: 'second', component: SecondActivity, back: nameOfRouteOrPathOrObject },
And the "back" method will simply look, whether there is a record in the routing or not. In #575 You said that this is about the local state. But it seems to me that this is about routing...
Hi, thanks for your interest but Github issues are for bug reports and feature requests only. You can ask questions on the forum, the Discord server, gitter or StackOverflow.
Use router.go(-1)
Ok. I will repeat :stuck_out_tongue:
This does not work if there is no history. I need to do my own thing?..
In #575 You said that this is about the local state. But it seems to me that this is about routing...
Probably routing is not only going forward.
When there is no history in the browser, the router does _not have the ability_ to go back normally.
yeah, you'll need to use plain javascript for that. Please, use the forum, discord or so next time for questions 馃檪
@tebaly Thank you for the example by this.$route.meta
Hi,
for me i solve this issue as following
niceback: function(){
var numberOfEntries = window.history.length;
if(numberOfEntries>2){
this.$router.go(-1)
}else{
var fpath= this.PageData.backCrumb.url;
this.$router.push({
path: fpath
})
}
},
hope it will help you!
Most helpful comment
Hi, thanks for your interest but Github issues are for bug reports and feature requests only. You can ask questions on the forum, the Discord server, gitter or StackOverflow.
Use
router.go(-1)