StackedRouter: add replace: all
This commit is contained in:
parent
4c717a0cb7
commit
83e2e6e169
2 changed files with 15 additions and 7 deletions
|
@ -64,7 +64,7 @@ export function useSessions() {
|
||||||
if (sessions().length > 0) return;
|
if (sessions().length > 0) return;
|
||||||
push(
|
push(
|
||||||
"/accounts/sign-in?back=" + encodeURIComponent(location.pathname),
|
"/accounts/sign-in?back=" + encodeURIComponent(location.pathname),
|
||||||
{ replace: true },
|
{ replace: "all" },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,9 @@ export type NewFrameOptions<T> = (T extends undefined
|
||||||
}
|
}
|
||||||
: { state: T }) & {
|
: { state: T }) & {
|
||||||
/**
|
/**
|
||||||
* The new frame should replace the current frame.
|
* The new frame should replace the current frame or all the stack.
|
||||||
*/
|
*/
|
||||||
replace?: boolean;
|
replace?: boolean | "all";
|
||||||
/**
|
/**
|
||||||
* The animatedOpen phase of the life cycle.
|
* The animatedOpen phase of the life cycle.
|
||||||
*
|
*
|
||||||
|
@ -427,11 +427,19 @@ const StackedRouter: Component<StackedRouterProps> = (oprops) => {
|
||||||
animateClose: opts?.animateClose,
|
animateClose: opts?.animateClose,
|
||||||
};
|
};
|
||||||
|
|
||||||
mutStack(opts?.replace ? stack.length - 1 : stack.length, frame);
|
const replace = opts?.replace;
|
||||||
if (opts?.replace) {
|
if (replace === "all") {
|
||||||
window.history.replaceState(serializableStack(stack), "", path);
|
mutStack([frame]);
|
||||||
} else {
|
} else {
|
||||||
window.history.pushState(serializableStack(stack), "", path);
|
mutStack(replace ? stack.length - 1 : stack.length, frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
const savedStack = serializableStack(stack);
|
||||||
|
|
||||||
|
if (replace) {
|
||||||
|
window.history.replaceState(savedStack, "", path);
|
||||||
|
} else {
|
||||||
|
window.history.pushState(savedStack, "", path);
|
||||||
}
|
}
|
||||||
return frame;
|
return frame;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue