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,
|
lastChild: number,
|
||||||
positionalParamSegments: {[k: string]: UrlPathWithParams}
|
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)) {
|
if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) {
|
||||||
throw new NoMatch();
|
throw new NoMatch();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,11 +3,6 @@ import {Type} from '@angular/core';
|
||||||
export type RouterConfig = Route[];
|
export type RouterConfig = Route[];
|
||||||
|
|
||||||
export interface Route {
|
export interface Route {
|
||||||
/**
|
|
||||||
* Use `path: ''` instead.
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
index?: boolean;
|
|
||||||
path?: string;
|
path?: string;
|
||||||
terminal?: boolean;
|
terminal?: boolean;
|
||||||
component?: Type|string;
|
component?: Type|string;
|
||||||
|
|
|
@ -111,7 +111,7 @@ function processPathsWithParamsAgainstRoute(
|
||||||
}
|
}
|
||||||
|
|
||||||
function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) {
|
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)) {
|
if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) {
|
||||||
throw new NoMatch();
|
throw new NoMatch();
|
||||||
} else {
|
} 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", () => {
|
describe("matching empty url", () => {
|
||||||
it("should support root index routes", () => {
|
it("should support root index routes", () => {
|
||||||
recognize(RootComponent, [
|
recognize(RootComponent, [
|
||||||
|
|
|
@ -261,7 +261,7 @@ describe("Integration", () => {
|
||||||
advance(fixture);
|
advance(fixture);
|
||||||
|
|
||||||
router.resetConfig([
|
router.resetConfig([
|
||||||
{ index: true, component: SimpleCmp },
|
{ path: '', terminal: true, component: SimpleCmp },
|
||||||
{ path: '/user/:name', component: UserCmp }
|
{ path: '/user/:name', component: UserCmp }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue