Improved navigation and room handling
This commit is contained in:
parent
8d652767be
commit
8555436bc7
10 changed files with 229 additions and 164 deletions
|
|
@ -1,6 +1,7 @@
|
|||
export default {
|
||||
install(Vue, router) {
|
||||
var routes = [];
|
||||
var nextRoutes = null;
|
||||
var zeroIndex = undefined;
|
||||
|
||||
router.beforeResolve((to, ignoredfrom, next) => {
|
||||
|
|
@ -12,20 +13,15 @@ export default {
|
|||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const index = routes.findIndex((item) => {
|
||||
return item.path == to.path || item.name == to.name;
|
||||
});
|
||||
if (index < 0 && routes.length > 0) {
|
||||
next(routes[0]);
|
||||
return;
|
||||
}
|
||||
// If we have a room id param, it needs to be the same, else we call "next" with the correct one
|
||||
if (index >= 0 && routes[index].params && to.params && routes[index].params.roomId != to.params.roomId) {
|
||||
next(routes[0]);
|
||||
return;
|
||||
}
|
||||
if (index >= 0) {
|
||||
routes.splice(index + 1);
|
||||
if (this.nextRoutes) {
|
||||
console.log("Nav: next routes set, going:", this.routes, this.nextRoutes);
|
||||
this.routes = this.nextRoutes;
|
||||
this.nextRoutes = null;
|
||||
if (this.routes.length > 0) {
|
||||
console.log("Redirecting to", this.routes.lastItem());
|
||||
next(this.routes.lastItem());
|
||||
return;
|
||||
}
|
||||
}
|
||||
next();
|
||||
})
|
||||
|
|
@ -40,7 +36,7 @@ export default {
|
|||
}
|
||||
if (mode == -1) {
|
||||
const i = routes.length - 1;
|
||||
routes = [route];
|
||||
nextRoutes = [route];
|
||||
if (i > 0) {
|
||||
router.go(-i);
|
||||
} else {
|
||||
|
|
@ -48,20 +44,27 @@ export default {
|
|||
}
|
||||
} else if (mode == 0) {
|
||||
// Replace
|
||||
routes.pop()
|
||||
routes.push(route);
|
||||
nextRoutes = [...routes];
|
||||
nextRoutes.pop();
|
||||
nextRoutes.push(route);
|
||||
router.replace(route).catch((ignoredErr) => {});
|
||||
} else {
|
||||
routes.push(route);
|
||||
nextRoutes = [...routes];
|
||||
nextRoutes.push(route);
|
||||
router.push(route).catch((ignoredErr) => {});
|
||||
}
|
||||
},
|
||||
|
||||
canPop() {
|
||||
if (nextRoutes) {
|
||||
return nextRoutes.length > 1;
|
||||
}
|
||||
return routes.length > 1;
|
||||
},
|
||||
|
||||
pop() {
|
||||
nextRoutes = [...routes];
|
||||
nextRoutes.pop();
|
||||
router.go(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue