Skip to content

Commit

Permalink
feat(router): keepSectionSlice for redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd authored and njfamirm committed Feb 25, 2023
1 parent 4c5f669 commit 1c3b370
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/router/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,19 @@ export const url = (route: Partial<RouteContextBase>): string => {
* })
* ```
*/
export const redirect = (route: string | RouteContextBase | undefined, pushState: PushState = true): void => {
export const redirect = (
route: string | Partial<RouteContextBase> | undefined,
pushState: PushState = true,
keepSectionSlice = 0,
): void => {
if (route == null) return;
logger.logMethodArgs('redirect', route);
if (keepSectionSlice > 0 && typeof route === 'object' && Array.isArray(route.sectionList)) {
const routeContext = routeContextConsumer.getValue();
if (routeContext != null) {
route.sectionList = [...routeContext.sectionList.slice(0, keepSectionSlice), ...route.sectionList];
}
}
const href = typeof route === 'string' ? route : url(route);
updateBrowserHistory(href, pushState);
routeContextProvider.setValue(makeRouteContext(), {debounce: 'Timeout'});
Expand Down

0 comments on commit 1c3b370

Please sign in to comment.