mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
Addresses some cleanup items for the router tree: - No longer loads router ng global APIs as a side effect of importing the router. Rather this is now a runtime step that occurs when provideRouter is called. - No longer depends on router.navigateByUrl in Angular DevTools. There is now a dedicated global util for this - Router instance logic no longer depends on token name - Prevents navigating to lazy or redirect routes (these don't have an associated component) PR Close #63081
192 lines
5 KiB
TypeScript
192 lines
5 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
*/
|
|
|
|
import {parseRoutes} from './router-tree';
|
|
|
|
describe('parseRoutes', () => {
|
|
it('should work without any routes', () => {
|
|
const routes: any[] = [];
|
|
const parsedRoutes = parseRoutes(routes as any);
|
|
expect(parsedRoutes).toEqual({
|
|
component: 'no-name',
|
|
path: '/',
|
|
children: [],
|
|
data: [],
|
|
isAux: false,
|
|
isLazy: false,
|
|
isActive: false,
|
|
isRedirect: false,
|
|
});
|
|
});
|
|
|
|
it('should work with single route', () => {
|
|
const nestedRouter = {
|
|
rootComponentType: {
|
|
name: 'homeComponent',
|
|
},
|
|
config: [],
|
|
};
|
|
const parsedRoutes = parseRoutes(nestedRouter as any);
|
|
expect(parsedRoutes).toEqual({
|
|
'component': 'homeComponent',
|
|
'path': '/',
|
|
'data': [],
|
|
'children': [],
|
|
'isAux': false,
|
|
'isLazy': false,
|
|
'isActive': false,
|
|
isRedirect: false,
|
|
});
|
|
});
|
|
|
|
it('should work with nested routes', () => {
|
|
const nestedRouter = {
|
|
rootComponentType: {
|
|
name: 'homeComponent',
|
|
},
|
|
config: [
|
|
{
|
|
outlet: 'outlet',
|
|
path: 'component-one',
|
|
component: {
|
|
name: 'component-one',
|
|
},
|
|
},
|
|
{
|
|
path: 'component-two',
|
|
component: {
|
|
name: 'component-two',
|
|
},
|
|
data: {
|
|
name: 'component-two',
|
|
},
|
|
children: [
|
|
{
|
|
path: 'component-two-two',
|
|
component: {
|
|
name: 'component-two-two',
|
|
},
|
|
_loadedConfig: {
|
|
routes: [
|
|
{
|
|
path: 'component-two-two-two',
|
|
component: {
|
|
name: 'component-two-two-two',
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
loadChildren: true,
|
|
path: 'lazy',
|
|
},
|
|
{
|
|
path: 'redirect',
|
|
redirectTo: 'redirectTo',
|
|
},
|
|
],
|
|
};
|
|
const parsedRoutes = parseRoutes(nestedRouter as any);
|
|
expect(parsedRoutes).toEqual({
|
|
'component': 'homeComponent',
|
|
'path': '/',
|
|
'children': [
|
|
{
|
|
'component': 'component-one',
|
|
'canActivateGuards': [],
|
|
'canActivateChildGuards': [],
|
|
'canMatchGuards': [],
|
|
'canDeactivateGuards': [],
|
|
'providers': [],
|
|
'path': '/(outlet:component-one)',
|
|
'title': '[Function]',
|
|
'pathMatch': undefined,
|
|
'data': [],
|
|
'isAux': true,
|
|
'isLazy': false,
|
|
'isActive': undefined,
|
|
'isRedirect': false,
|
|
},
|
|
{
|
|
'component': 'component-two',
|
|
'canActivateGuards': [],
|
|
'canActivateChildGuards': [],
|
|
'canMatchGuards': [],
|
|
'canDeactivateGuards': [],
|
|
'providers': [],
|
|
'path': '/component-two',
|
|
'title': '[Function]',
|
|
'pathMatch': undefined,
|
|
'data': [{'key': 'name', 'value': 'component-two'}],
|
|
'isAux': false,
|
|
'isLazy': false,
|
|
'isActive': undefined,
|
|
'isRedirect': false,
|
|
'children': [
|
|
{
|
|
'component': 'component-two-two',
|
|
'canActivateGuards': [],
|
|
'canActivateChildGuards': [],
|
|
'canMatchGuards': [],
|
|
'canDeactivateGuards': [],
|
|
'providers': [],
|
|
'path': '/component-two/component-two-two',
|
|
'title': '[Function]',
|
|
'pathMatch': undefined,
|
|
'data': [],
|
|
'isAux': false,
|
|
'isLazy': false,
|
|
'isActive': undefined,
|
|
'isRedirect': false,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
'component': 'lazy [Lazy]',
|
|
'canActivateGuards': [],
|
|
'canActivateChildGuards': [],
|
|
'canMatchGuards': [],
|
|
'canDeactivateGuards': [],
|
|
'providers': [],
|
|
'path': '/lazy',
|
|
'title': '[Function]',
|
|
'pathMatch': undefined,
|
|
'data': [],
|
|
'isAux': false,
|
|
'isLazy': true,
|
|
'isActive': undefined,
|
|
'isRedirect': false,
|
|
},
|
|
{
|
|
'component': 'redirect -> redirecting to -> "redirectTo"',
|
|
'canActivateGuards': [],
|
|
'canActivateChildGuards': [],
|
|
'canMatchGuards': [],
|
|
'canDeactivateGuards': [],
|
|
'providers': [],
|
|
'path': '/redirect',
|
|
'title': '[Function]',
|
|
'pathMatch': undefined,
|
|
'data': [],
|
|
'isAux': false,
|
|
'isLazy': false,
|
|
'isActive': undefined,
|
|
'isRedirect': true,
|
|
},
|
|
],
|
|
'isAux': false,
|
|
'isLazy': false,
|
|
'isRedirect': false,
|
|
'data': [],
|
|
'isActive': false,
|
|
} as any);
|
|
});
|
|
});
|