Angular route guards; how to allow changing URL parameter on same component?

Discussão em 'Angular' iniciado por Wouter van Koppen, Novembro 25, 2024.

  1. In my Angular app, I want to prevent the user from navigating away from a component by using a CanDeactivateGuard.

    But I want the user to allow to navigate to a different url parameter id within FeatureBComponent. After adding a CanDeactivateGuard, it blocks every path change. To allow the path parameter change, I came across the RunGuardsAndResolvers config parameter.

    But that only supports ignoring query and matrix parameters, not path parameters.

    I also tried to tackle ignoring the path parameter change in the guard itself by checking the nextState parameter, but nextState.url still gives back the current URL. So that cannot be used to check.

    So in short, how can I allow the user to navigate between

    /overview/1

    /overview/2


    but not

    /someotheroute


    ?

    Continue reading...

Compartilhe esta Página