Skip to content

Commit

Permalink
fix(router): fixed issue for routable swipeable tabs with dynamic par…
Browse files Browse the repository at this point in the history
…ams in route path
  • Loading branch information
nolimits4web committed May 28, 2021
1 parent df64010 commit 4a93d90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/core/components/swiper/swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ function initSwiper(swiperEl) {
let view = app.views.get($swiperEl.parents('.view'));
if (!view) view = app.views.main;
const router = view.router;
const tabRoute = router.findTabRoute(swiper.slides.eq(swiper.activeIndex)[0]);
if (tabRoute) {
const tabRouteUrl = router.findTabRouteUrl(swiper.slides.eq(swiper.activeIndex)[0]);
if (tabRouteUrl) {
setTimeout(() => {
router.navigate(tabRoute.path);
router.navigate(tabRouteUrl);
}, 0);
}
} else {
Expand Down
12 changes: 8 additions & 4 deletions src/core/modules/router/router-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,19 +601,23 @@ class Router extends Framework7Class {
return url;
}

findTabRoute(tabEl) {
findTabRouteUrl(tabEl) {
const router = this;
const $tabEl = $(tabEl);
const parentPath = router.currentRoute.route.parentPath;
const tabId = $tabEl.attr('id');
const flattenedRoutes = router.flattenRoutes(router.routes);
let foundTabRoute;
let foundTabRouteUrl;
flattenedRoutes.forEach((route) => {
if (route.parentPath === parentPath && route.tab && route.tab.id === tabId) {
foundTabRoute = route;
if (router.currentRoute.params && Object.keys(router.currentRoute.params).length > 0) {
foundTabRouteUrl = router.currentRoute.url;
} else {
foundTabRouteUrl = route.path;
}
}
});
return foundTabRoute;
return foundTabRouteUrl;
}

findRouteByKey(key, value) {
Expand Down

0 comments on commit 4a93d90

Please sign in to comment.