* Executes the beforeLeave hook of the source route and the beforeEnter hook of the target route if they exist. * * When the beforeLeave hook does not return true (to allow navigating) then that value is returned early and the beforeEnter is executed. * Otherwise the beforeEnterHook hook of
(
to: string[] | null = this.getSegments(),
from?: string[] | null
)
| 324 | * Otherwise the beforeEnterHook hook of the target route is executed. |
| 325 | */ |
| 326 | private async runGuards( |
| 327 | to: string[] | null = this.getSegments(), |
| 328 | from?: string[] | null |
| 329 | ): Promise<NavigationHookResult> { |
| 330 | if (from === undefined) { |
| 331 | from = parsePath(this.previousPath).segments; |
| 332 | } |
| 333 | |
| 334 | if (!to || !from) { |
| 335 | return true; |
| 336 | } |
| 337 | |
| 338 | const routes = readRoutes(this.el); |
| 339 | |
| 340 | const fromChain = findChainForSegments(from, routes); |
| 341 | // eslint-disable-next-line @typescript-eslint/prefer-optional-chain |
| 342 | const beforeLeaveHook = fromChain && fromChain[fromChain.length - 1].beforeLeave; |
| 343 | |
| 344 | const canLeave = beforeLeaveHook ? await beforeLeaveHook() : true; |
| 345 | if (canLeave === false || typeof canLeave === 'object') { |
| 346 | return canLeave; |
| 347 | } |
| 348 | |
| 349 | const toChain = findChainForSegments(to, routes); |
| 350 | // eslint-disable-next-line @typescript-eslint/prefer-optional-chain |
| 351 | const beforeEnterHook = toChain && toChain[toChain.length - 1].beforeEnter; |
| 352 | |
| 353 | return beforeEnterHook ? beforeEnterHook() : true; |
| 354 | } |
| 355 | |
| 356 | private async writeNavState( |
| 357 | node: HTMLElement | undefined, |
no test coverage detected