docs(router): rename global redirects into absolute redirects

This commit is contained in:
vsavkin 2016-06-30 13:26:56 -07:00
parent 3cbded6694
commit 81bf3f66ca
3 changed files with 9 additions and 9 deletions

View File

@ -18,7 +18,7 @@ import {merge} from './utils/collection';
class NoMatch {
constructor(public segment: UrlSegment = null) {}
}
class GlobalRedirect {
class AbsoluteRedirect {
constructor(public paths: UrlPathWithParams[]) {}
}
@ -26,7 +26,7 @@ export function applyRedirects(urlTree: UrlTree, config: RouterConfig): Observab
try {
return createUrlTree(urlTree, expandSegment(config, urlTree.root, PRIMARY_OUTLET));
} catch (e) {
if (e instanceof GlobalRedirect) {
if (e instanceof AbsoluteRedirect) {
return createUrlTree(
urlTree, new UrlSegment([], {[PRIMARY_OUTLET]: new UrlSegment(e.paths, {})}));
} else if (e instanceof NoMatch) {
@ -98,7 +98,7 @@ function expandPathsWithParamsAgainstRouteUsingRedirect(
function expandWildCardWithParamsAgainstRouteUsingRedirect(route: Route): UrlSegment {
const newPaths = applyRedirectCommands([], route.redirectTo, {});
if (route.redirectTo.startsWith('/')) {
throw new GlobalRedirect(newPaths);
throw new AbsoluteRedirect(newPaths);
} else {
return new UrlSegment(newPaths, {});
}
@ -111,7 +111,7 @@ function expandRegularPathWithParamsAgainstRouteUsingRedirect(
const newPaths =
applyRedirectCommands(consumedPaths, route.redirectTo, <any>positionalParamSegments);
if (route.redirectTo.startsWith('/')) {
throw new GlobalRedirect(newPaths);
throw new AbsoluteRedirect(newPaths);
} else {
return expandPathsWithParams(
segment, routes, newPaths.concat(paths.slice(lastChild)), outlet, false);

View File

@ -94,7 +94,7 @@ import {Type} from '@angular/core';
* '/team/11/user/jim', and then will instantiate the team component with the user component
* in it.
*
* If the `redirectTo` value starts with a '/', then it is a global redirect. E.g., if in the
* If the `redirectTo` value starts with a '/', then it is an absolute redirect. E.g., if in the
* example above we change the `redirectTo` to `/user/:name`, the result url will be '/user/jim'.
*
* ### Empty Path

View File

@ -115,17 +115,17 @@ describe('applyRedirects', () => {
'/a/1(aux:c/d)', (t: UrlTree) => { compareTrees(t, tree('/404')); });
});
it('should support global redirects', () => {
it('should support absolute redirects', () => {
checkRedirect(
[
{
path: 'a',
component: ComponentA,
children: [{path: 'b/:id', redirectTo: '/global/:id'}]
children: [{path: 'b/:id', redirectTo: '/absolute/:id'}]
},
{path: '**', component: ComponentC}
],
'/a/b/1', (t: UrlTree) => { compareTrees(t, tree('/global/1')); });
'/a/b/1', (t: UrlTree) => { compareTrees(t, tree('/absolute/1')); });
});
describe('empty paths', () => {
@ -144,7 +144,7 @@ describe('applyRedirects', () => {
'b', (t: UrlTree) => { compareTrees(t, tree('a/b')); });
});
it('redirect from an empty path should work (global redirect)', () => {
it('redirect from an empty path should work (absolute redirect)', () => {
checkRedirect(
[
{