From 1c3b370c41f96a8ad612ea9fd5ab9963f6a3b27b Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Mon, 20 Feb 2023 03:02:15 +0330 Subject: [PATCH] feat(router): keepSectionSlice for redirect --- core/router/src/core.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/router/src/core.ts b/core/router/src/core.ts index de396663d..5d97cf4b0 100644 --- a/core/router/src/core.ts +++ b/core/router/src/core.ts @@ -123,9 +123,19 @@ export const url = (route: Partial): string => { * }) * ``` */ -export const redirect = (route: string | RouteContextBase | undefined, pushState: PushState = true): void => { +export const redirect = ( + route: string | Partial | 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'});