Skip to content
Closed
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
3 changes: 2 additions & 1 deletion packages/router/src/recognize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
} from './utils/config_matching';
import {TreeNode} from './utils/tree';
import {firstValueFrom} from './utils/first_value_from';
import {isEmptyError} from './utils/type_guards';

/**
* Class used to indicate there were no additional route config matches but that all segments of
Expand Down Expand Up @@ -257,7 +258,7 @@ export class Recognizer {
parentRoute,
);
} catch (e: any) {
if (e?.name === NO_MATCH_ERROR_NAME) {
if (e?.name === NO_MATCH_ERROR_NAME || isEmptyError(e)) {
continue;
}
throw e;
Expand Down
18 changes: 17 additions & 1 deletion packages/router/test/integration/guards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
EnvironmentInjector,
} from '@angular/core';
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {Subject, Observable, of, concat} from 'rxjs';
import {Subject, Observable, of, concat, EMPTY} from 'rxjs';
import {tap, mapTo, first, takeWhile, last, switchMap} from 'rxjs/operators';
import {
ActivatedRouteSnapshot,
Expand Down Expand Up @@ -2048,6 +2048,22 @@ export function guardsIntegrationSuite() {
await advance(fixture);
expect(fixture.nativeElement.innerHTML).toContain('simple');
});
it('falls back to second route when canMatch returns EMPTY', async () => {
const router = TestBed.inject(Router);
router.resetConfig([
{
path: 'a',
canMatch: [() => EMPTY],
component: BlankCmp,
},
{path: 'a', component: SimpleCmp},
]);
const fixture = await createRoot(router, RootCmp);

router.navigateByUrl('/a');
await advance(fixture);
expect(fixture.nativeElement.innerHTML).toContain('simple');
});

it('uses route when canMatch returns true', async () => {
const router = TestBed.inject(Router);
Expand Down