diff --git a/npm/ng-packs/packages/core/src/lib/actions/replaceable-components.actions.ts b/npm/ng-packs/packages/core/src/lib/actions/replaceable-components.actions.ts index 3b948cf63d..8df6a384ad 100644 --- a/npm/ng-packs/packages/core/src/lib/actions/replaceable-components.actions.ts +++ b/npm/ng-packs/packages/core/src/lib/actions/replaceable-components.actions.ts @@ -5,5 +5,8 @@ import { ReplaceableComponents } from '../models/replaceable-components'; */ export class AddReplaceableComponent { static readonly type = '[ReplaceableComponents] Add'; - constructor(public payload: ReplaceableComponents.ReplaceableComponent) {} + constructor( + public payload: ReplaceableComponents.ReplaceableComponent, + public reload?: boolean, + ) {} } diff --git a/npm/ng-packs/packages/core/src/lib/states/replaceable-components.state.ts b/npm/ng-packs/packages/core/src/lib/states/replaceable-components.state.ts index 7c07621ad4..0e48104f87 100644 --- a/npm/ng-packs/packages/core/src/lib/states/replaceable-components.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/replaceable-components.state.ts @@ -1,8 +1,9 @@ import { Injectable } from '@angular/core'; -import { State, Action, StateContext, Selector, createSelector } from '@ngxs/store'; +import { Router } from '@angular/router'; +import { Action, createSelector, Selector, State, StateContext } from '@ngxs/store'; +import snq from 'snq'; import { AddReplaceableComponent } from '../actions/replaceable-components.actions'; import { ReplaceableComponents } from '../models/replaceable-components'; -import snq from 'snq'; @State({ name: 'ReplaceableComponentsState', @@ -28,10 +29,12 @@ export class ReplaceableComponentsState { return selector; } + constructor(private router: Router) {} + @Action(AddReplaceableComponent) - replaceableComponentsAction( + async replaceableComponentsAction( { getState, patchState }: StateContext, - { payload }: AddReplaceableComponent, + { payload, reload }: AddReplaceableComponent, ) { let { replaceableComponents } = getState(); @@ -48,5 +51,15 @@ export class ReplaceableComponentsState { patchState({ replaceableComponents, }); + + if (reload) { + // TODO: Create a shared service for route reload and more + const { shouldReuseRoute } = this.router.routeReuseStrategy; + this.router.routeReuseStrategy.shouldReuseRoute = () => false; + this.router.navigated = false; + + await this.router.navigateByUrl(this.router.url).catch(); + this.router.routeReuseStrategy.shouldReuseRoute = shouldReuseRoute; + } } }