Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update upstream fix(RouterStore): Fix cancelled navigation with async guard (fixes #3… #13

Merged
merged 1 commit into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions modules/router-store/spec/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
} from '../src/index';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/first';
import 'rxjs/add/operator/mapTo';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/toPromise';
import { of } from 'rxjs/observable/of';

describe('integration spec', () => {
it('should work', done => {
Expand Down Expand Up @@ -370,6 +373,38 @@ describe('integration spec', () => {
});
});
});

it('should support event during an async canActivate guard', done => {
createTestModule({
reducers: { routerReducer },
canActivate: () => {
store.dispatch({ type: 'USER_EVENT' });
return store.take(1).mapTo(true);
},
});

const router: Router = TestBed.get(Router);
const store: Store<any> = TestBed.get(Store);
const log = logOfRouterAndStore(router, store);

router
.navigateByUrl('/')
.then(() => {
log.splice(0);
return router.navigateByUrl('next');
})
.then(() => {
expect(log).toEqual([
{ type: 'router', event: 'NavigationStart', url: '/next' },
{ type: 'router', event: 'RoutesRecognized', url: '/next' },
{ type: 'store', state: undefined }, // after ROUTER_NAVIGATION
{ type: 'store', state: undefined }, // after USER_EVENT
{ type: 'router', event: 'NavigationEnd', url: '/next' },
]);

done();
});
});
});

function createTestModule(
Expand Down
2 changes: 2 additions & 0 deletions modules/router-store/src/router_store_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export class StoreRouterConnectingModule {
private setUpStoreStateListener(): void {
this.store.subscribe(s => {
this.storeState = s;
});
this.store.select('routerReducer').subscribe(() => {
this.navigateIfNeeded();
});
}
Expand Down