-
Notifications
You must be signed in to change notification settings - Fork 20
Support navigateByUrl equivalent #30
Comments
Reasonable enough. I'll look into adding this soon. |
Second this. In our case we have an authentication guard that saves the requested URL, and after login we attempt to dispatch an action that redirects to that URL. Problem is, without being able to use an equivalent to |
As referenced, I've submitted a pull request that adds this feature. :) |
We have a case where we need to navigate to outlets and the url looks like |
Never mind, we'll be switching over to v4.x! |
nm I found it, looks like they moved all packages into one GitHub repo. https://github.com/ngrx/platform |
One thing still mystifies me: How can I do a navigation as part of an effect? Seems to me this is not possible anymore, without doing a .switchMap(action => {
this.router.navigate(['blah']);
return empty():
}) before it was easier: map.(() => go('blah')); |
@mischkl I believe you would just not dispatch an action:
And if you switch to v4 then the actions will be dispatched for you. |
@richarddavenport afaik you can't return a With the previous version the actions were dispatched just like in the new one. The main difference was that it offered actions with which you could trigger the router (e.g., |
@mischkl I'm talking about not dispatching an action... Pass { dispatch: false } to the decorator to prevent actions from being dispatched. It's my understanding that you use that when you don't want to return an action, meaning you can run any other side effects, including routing. Here is an example of doing it in the new monorepo: https://github.com/ngrx/platform/blob/master/example-app/app/auth/effects/auth.effects.ts#L27-L30 Here's the new documentation: https://github.com/ngrx/platform/blob/master/docs/effects/api.md#non-dispatching-effects |
Aha totally awesome, thx for the tip @richarddavenport! Very, very handy! And if you did the same thing with ngrx v3, you would create an endless loop! 😄 |
There are times when
go()
is not sufficient as it usesnavigate
method internally. For example, when passing redirection links with URL params inside, internal use ofnavigate
doesn't work well and params are not parsed properly. This can be solved by usingnavigateByUrl
.E.g. passing continue link with parameters:
/candidates/57f39a88720e1a181134ae25;back=%2Fcandidates
This doesn't work well when doing
go('/candidates/57f39a88720e1a181134ae25;back=%2Fcandidates')
. Theback
parameter is not parsed properly and angular2 thinks it's actually the:id
parameter in route definition (/candidates/:id
). Instead, I have to userouter.navigateByUrl('/57f39a88720e1a181134ae25;back=%2Fcandidates')
which ensures the parsing is being done.The text was updated successfully, but these errors were encountered: