feat(router): drop index property
Use path: '/' instead of 'index: true'
This commit is contained in:
parent
f8e8d22e4e
commit
2773281338
|
@ -135,7 +135,7 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]): {
|
|||
lastChild: number,
|
||||
positionalParamSegments: {[k: string]: UrlPathWithParams}
|
||||
} {
|
||||
if (route.index || route.path === '' || route.path === '/') {
|
||||
if (route.path === '' || route.path === '/') {
|
||||
if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) {
|
||||
throw new NoMatch();
|
||||
} else {
|
||||
|
|
|
@ -3,11 +3,6 @@ import {Type} from '@angular/core';
|
|||
export type RouterConfig = Route[];
|
||||
|
||||
export interface Route {
|
||||
/**
|
||||
* Use `path: ''` instead.
|
||||
* @deprecated
|
||||
*/
|
||||
index?: boolean;
|
||||
path?: string;
|
||||
terminal?: boolean;
|
||||
component?: Type|string;
|
||||
|
|
|
@ -111,7 +111,7 @@ function processPathsWithParamsAgainstRoute(
|
|||
}
|
||||
|
||||
function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) {
|
||||
if (route.index || route.path === '' || route.path === '/') {
|
||||
if (route.path === '' || route.path === '/') {
|
||||
if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) {
|
||||
throw new NoMatch();
|
||||
} else {
|
||||
|
|
|
@ -158,63 +158,6 @@ describe('recognize', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("index", () => {
|
||||
it("should support root index routes", () => {
|
||||
checkRecognize([
|
||||
{index: true, component: ComponentA}
|
||||
], "", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
});
|
||||
});
|
||||
|
||||
it("should support nested root index routes", () => {
|
||||
checkRecognize([
|
||||
{index: true, component: ComponentA, children: [{index: true, component: ComponentB}]}
|
||||
], "", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
});
|
||||
});
|
||||
|
||||
it("should support index routes", () => {
|
||||
checkRecognize([
|
||||
{path: 'a', component: ComponentA, children: [
|
||||
{index: true, component: ComponentB}
|
||||
]}
|
||||
], "a", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
});
|
||||
});
|
||||
|
||||
it("should support index routes with children", () => {
|
||||
checkRecognize([
|
||||
{
|
||||
index: true, component: ComponentA, children: [
|
||||
{ index: true, component: ComponentB, children: [
|
||||
{path: 'c/:id', component: ComponentC}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
], "c/10", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
checkActivatedRoute(
|
||||
s.firstChild(<any>s.firstChild(<any>s.firstChild(s.root))), "c/10", {id: '10'}, ComponentC);
|
||||
});
|
||||
});
|
||||
|
||||
xit("should pass parameters to every nested index route (case with non-index route)", () => {
|
||||
checkRecognize([
|
||||
{path: 'a', component: ComponentA, children: [{index: true, component: ComponentB}]}
|
||||
], "/a;a=1", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "a", {a: '1'}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {a: '1'}, ComponentB);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("matching empty url", () => {
|
||||
it("should support root index routes", () => {
|
||||
recognize(RootComponent, [
|
||||
|
|
|
@ -259,9 +259,9 @@ describe("Integration", () => {
|
|||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
||||
router.resetConfig([
|
||||
{ index: true, component: SimpleCmp },
|
||||
{ path: '', terminal: true, component: SimpleCmp },
|
||||
{ path: '/user/:name', component: UserCmp }
|
||||
]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue