Skip to content

Commit 25e9d98

Browse files
committed
fix(plugin-context-navigation): preserve sub-route on context change
The path adapter previously dropped the sub-route on every context encode, including when context changed (not just when cleared). Only drop the sub-route when context becomes null, since there's no valid context to resolve it against. Fixes: equinor/fusion#904
1 parent a9c9c95 commit 25e9d98

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@equinor/fusion-framework-plugin-context-navigation": patch
3+
---
4+
5+
Fix the path adapter to preserve the app's sub-route when the context changes, instead of always resetting to the app root. The sub-route is still dropped when context is cleared entirely, since there's no valid context to resolve it against.
6+
7+
Fixes: https://github.com/equinor/fusion/issues/904

packages/plugins/context-navigation/src/adapters/create-path-adapter.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,21 @@ export function createPathAdapter(): ContextNavigationAdapter {
6868
/**
6969
* Encode context into the URL as a path segment.
7070
*
71-
* - **Null context:** removes the context segment to produce a bare app route.
72-
* - **Active context:** places/replaces the context id as the segment after the app key.
73-
*
74-
* Sub-routes after the context segment are intentionally dropped — a context
75-
* change resets the app to its root view to avoid landing in an invalid state.
71+
* - **Null context:** removes the context segment and drops any sub-route,
72+
* resetting the app to its root view — there's no valid context to resolve
73+
* the sub-route against.
74+
* - **Active context:** places/replaces the context id as the segment after
75+
* the app key, preserving the existing sub-route.
7676
*/
7777
encode({ context, currentURL }: { context: ContextItem | null; currentURL: URL }): URL | null {
7878
const match = parseAppRoute(currentURL.pathname);
7979
// Pathname doesn't match the /apps/{key}/... shape — not a Fusion app route, bail out
8080
if (!match) return null;
8181

8282
const targetPath =
83-
context === null ? buildAppRoute(match.appKey) : buildAppRoute(match.appKey, context.id);
83+
context === null
84+
? buildAppRoute(match.appKey)
85+
: buildAppRoute(match.appKey, context.id, match.rest);
8486

8587
const url = new URL(targetPath, currentURL.origin);
8688
url.search = currentURL.search;

0 commit comments

Comments
 (0)