2

I don't find any documentation on this precious behaviour of Angular 2 Router : if I load my app with a 'state' query param, the router automatically navigates to the given state.

I found this by chance looking for a solution to my problem, but I need to parse some other query params and here I'm loosing them.

For example : http://my.app/?state=#/screen1&anotherParam=something automatically "redirect" my application to http://my.app/#/screen1, then I'm loosing anotherParam.

Is this a undocumented feature or a bug ? Or do you see any page I missed about this behaviour ?

Karbos 538
  • 2,977
  • 1
  • 23
  • 34

1 Answers1

2

This is a known issue

As a workaround you could add a guard that covers all routes, when the guard is called store the params in a shared service and provide them this way to interested components.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Thanks for your answer. I think your suggestion "guard that covers all routes" will finally solve my real problem. But my post was about the magic feature with 'state' query param... – Karbos 538 Jan 10 '17 at 15:07
  • What does "the router automatically navigates to the given state" even mean? How do your routes look like? – Günter Zöchbauer Jan 10 '17 at 15:08
  • I'm using hash strategy. "the router automatically navigates to the given state" i.e "to the given route" – Karbos 538 Jan 10 '17 at 15:09
  • No idea what you mean. One of the main features of the router is to allow to create bookmarks for application states. If you click a bookmark to a specific route or enter the URL directly the router navigates to this route. Is this what you mean? – Günter Zöchbauer Jan 10 '17 at 15:12
  • 1
    OK I was wrong, my hash was not encoded so I was in the issue you point. Thanks – Karbos 538 Jan 10 '17 at 15:22