angular 4 router without router-outlet

2019-04-09 21:15发布

问题:

I am currently implementing a custom state management in angular 4 based on angular router, basically without any router-outlet attaching and detaching components myself based on routing events.

It works fine until i try to navigate from a route with parameters to the same route with different parameters, then it crashes.

This plunkr ( watch the console ) explains my situation. Navigating from 'crisis center' to 'heroes' is fine, navigating from 'heroes' to 'hero 11' is fine, navigating from 'hero11' to 'hero12' throws the error

TypeError: Cannot read property 'component' of null

I know the router is supposed to work with an outlet, but i think it's weird that without it works partially, so I'm not even sure if this can be considered a bug or desired behavior.

I'm wondering if there's some configuration option that would allow this particular situation or should i just use another routing library and avoid the angular router?

回答1:

This issue is solved by adding a 'never' configuration parameter to the Route's runGuardsAndResolvers configuration option, as seen in this commit.