Skip to content

Commit

Permalink
fix: woopsie on relative navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinderoubaix committed Jan 17, 2024
1 parent 88f02c7 commit ffe820b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions demo/src/lib/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import {computed, get} from '@amadeus-it-group/tansu';
import {browser} from '$app/environment';
import {page} from '$app/stores';
import {createIntersection} from '@agnos-ui/core/services/intersection';
import {resolveRoute} from '$app/paths';

export const resolvedRoute$ = computed(() => {
// Return how deep the current route is compared to base
export const routeLevel$ = computed(() => {
const $page = get(page);
return $page.route.id ? resolveRoute($page.route.id, $page.params) : './';
if (!$page.route.id) {
throw new Error('Page error');
}
return $page.route.id.split('/').length - 2 + Object.values($page.params).reduce((pV, cur) => pV + cur.split('/').length - 1, 0);
});

// Return how deep the current route is compared to base
export const routeLevel$ = computed(() => resolvedRoute$().split('/').length - 2);

// Return the url relative path to root, ex './', '../' or '../..'
export const relativePathToRoot$ = computed(() => {
const routeLevel = routeLevel$();
Expand Down Expand Up @@ -46,7 +46,11 @@ export const selectedTabName$ = computed(() => {
return match?.[1] || 'examples';
});

const frameworkKeyRegExp = /^\/docs\/[a-z]*\//;
export const frameworkLessUrl$ = computed(() => resolvedRoute$().replace(frameworkKeyRegExp, ''));
const frameworkKeyRegExp = /\/docs\/[a-z]*\//;
export const frameworkLessUrl$ = computed(() => {
const $page = get(page);
const match = $page.url.pathname.match(frameworkKeyRegExp);
return match ? $page.url.pathname.substring($page.url.pathname.indexOf(match[0]) + match[0].length) : '/';
});

export const intersectionApi = createIntersection();

0 comments on commit ffe820b

Please sign in to comment.