Before there was a go action I use this way:
import { go } from '@ngrx/router-store';
...
@Effect()
logoutSuccess$: Observable<Action> = this.actions$
.ofType(authentication.LOGOUT_SUCCESS)
.map(_ =>
go('/login')
);
There's no "go" action anymore in new releases and the examples are not showing anything similar to this. Is still possible?
Thank you!
https://github.com/ngrx/platform/issues/107
There isn't a replacement for those actions in V4 and that's for consistency. You should use the router navigation syntax as normal. If you're using the actions in effects, you would inject the Router and use it to navigate rather than dispatching an action that tells the router to navigate.
The migration guide should probably have mentioned this, but it doesnt.
This is the solution I adopt:
.do(_ => this.router.navigate['/login']);
but the app stop working, freezing the browser. Looking at the stacktrace, it seems that the call to "do" method starts a loop. I'm sure to do something wrong, but maybe could be a bug in library.
Do you have any example code?
Your action LOGOUT_SUCCESS is being sent and then received again. You could potentially add
@Effect({ dispatch: false }) to this effect. This is because the last created action is returned from your effect. Previously, you had a GoAction and this was not being picked up again by the same action (which was not causing the infiniate loop). However now the last action is the same one its listening for (LOGOUT_SUCCESS) and so it returns LOGOUT_SUCCESS and then it gets stuck. You could maybe map the LOGOUT_SUCCESS to a new Action of your own such as LOGOUT_SUCCESS_NAVIGATE and then use the .do(_ => this.router.navigate['/login']) This is because the this.router.navigate['/login'] does not return an Action like the go did. And so the .do(_ => ...) function simply returns the last Action known.
Ok, amazing answer! Thank you very much, I'm really happy to see my app working after all these refactorings!!! :D
Most helpful comment
Your action LOGOUT_SUCCESS is being sent and then received again. You could potentially add
@Effect({ dispatch: false })to this effect. This is because the last created action is returned from your effect. Previously, you had a GoAction and this was not being picked up again by the same action (which was not causing the infiniate loop). However now the last action is the same one its listening for (LOGOUT_SUCCESS) and so it returns LOGOUT_SUCCESS and then it gets stuck. You could maybe map the LOGOUT_SUCCESS to a new Action of your own such as LOGOUT_SUCCESS_NAVIGATE and then use the.do(_ => this.router.navigate['/login'])This is because thethis.router.navigate['/login']does not return anActionlike thegodid. And so the.do(_ => ...)function simply returns the last Action known.