Skip to content

Commit 8e59028

Browse files
author
farfromrefug
committedJul 2, 2024
fix: allow backStackEntry to be passed directly to goBack
1 parent 39b8554 commit 8e59028

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed
 

‎src/dom/navigation.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export function navigate<T>(options: NavigationOptions<T>): SvelteComponent<T> {
9696
export interface BackNavigationOptions {
9797
frame?: FrameSpec;
9898
to?: PageElement;
99+
backStackEntry?: BackstackEntry;
99100

100101
// only in Akylas fork for now
101102
transition?: NavigationTransition;
@@ -108,17 +109,19 @@ export function goBack(options: BackNavigationOptions = {}) {
108109
if (!targetFrame) {
109110
throw new Error("goback requires frame option to be a native Frame, a FrameElement, a frame Id, or null")
110111
}
111-
let backStackEntry: BackstackEntry = null;
112-
if (options.to) {
113-
backStackEntry = targetFrame.backStack.find(e => e.resolvedPage === options.to.nativeView);
114-
if (!backStackEntry) {
115-
throw new Error("Couldn't find the destination page in the frames backstack")
112+
let backStackEntry: BackstackEntry = options.backStackEntry;
113+
if (!backStackEntry) {
114+
if (options.to) {
115+
backStackEntry = targetFrame.backStack.find(e => e.resolvedPage === options.to.nativeView);
116+
if (!backStackEntry) {
117+
throw new Error("Couldn't find the destination page in the frames backstack")
118+
}
119+
delete options.to;
120+
Object.assign(backStackEntry, options)
121+
} else {
122+
backStackEntry = targetFrame.backStack[targetFrame.backStack.length - 1];
123+
Object.assign(backStackEntry, options)
116124
}
117-
delete options.to;
118-
Object.assign(backStackEntry, options)
119-
} else {
120-
backStackEntry = targetFrame.backStack[targetFrame.backStack.length - 1];
121-
Object.assign(backStackEntry, options)
122125
}
123126
return targetFrame.goBack(backStackEntry);
124127
}

0 commit comments

Comments
 (0)