docs(router): rename global redirects into absolute redirects
This commit is contained in:
parent
3cbded6694
commit
81bf3f66ca
@ -18,7 +18,7 @@ import {merge} from './utils/collection';
|
|||||||
class NoMatch {
|
class NoMatch {
|
||||||
constructor(public segment: UrlSegment = null) {}
|
constructor(public segment: UrlSegment = null) {}
|
||||||
}
|
}
|
||||||
class GlobalRedirect {
|
class AbsoluteRedirect {
|
||||||
constructor(public paths: UrlPathWithParams[]) {}
|
constructor(public paths: UrlPathWithParams[]) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ export function applyRedirects(urlTree: UrlTree, config: RouterConfig): Observab
|
|||||||
try {
|
try {
|
||||||
return createUrlTree(urlTree, expandSegment(config, urlTree.root, PRIMARY_OUTLET));
|
return createUrlTree(urlTree, expandSegment(config, urlTree.root, PRIMARY_OUTLET));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof GlobalRedirect) {
|
if (e instanceof AbsoluteRedirect) {
|
||||||
return createUrlTree(
|
return createUrlTree(
|
||||||
urlTree, new UrlSegment([], {[PRIMARY_OUTLET]: new UrlSegment(e.paths, {})}));
|
urlTree, new UrlSegment([], {[PRIMARY_OUTLET]: new UrlSegment(e.paths, {})}));
|
||||||
} else if (e instanceof NoMatch) {
|
} else if (e instanceof NoMatch) {
|
||||||
@ -98,7 +98,7 @@ function expandPathsWithParamsAgainstRouteUsingRedirect(
|
|||||||
function expandWildCardWithParamsAgainstRouteUsingRedirect(route: Route): UrlSegment {
|
function expandWildCardWithParamsAgainstRouteUsingRedirect(route: Route): UrlSegment {
|
||||||
const newPaths = applyRedirectCommands([], route.redirectTo, {});
|
const newPaths = applyRedirectCommands([], route.redirectTo, {});
|
||||||
if (route.redirectTo.startsWith('/')) {
|
if (route.redirectTo.startsWith('/')) {
|
||||||
throw new GlobalRedirect(newPaths);
|
throw new AbsoluteRedirect(newPaths);
|
||||||
} else {
|
} else {
|
||||||
return new UrlSegment(newPaths, {});
|
return new UrlSegment(newPaths, {});
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ function expandRegularPathWithParamsAgainstRouteUsingRedirect(
|
|||||||
const newPaths =
|
const newPaths =
|
||||||
applyRedirectCommands(consumedPaths, route.redirectTo, <any>positionalParamSegments);
|
applyRedirectCommands(consumedPaths, route.redirectTo, <any>positionalParamSegments);
|
||||||
if (route.redirectTo.startsWith('/')) {
|
if (route.redirectTo.startsWith('/')) {
|
||||||
throw new GlobalRedirect(newPaths);
|
throw new AbsoluteRedirect(newPaths);
|
||||||
} else {
|
} else {
|
||||||
return expandPathsWithParams(
|
return expandPathsWithParams(
|
||||||
segment, routes, newPaths.concat(paths.slice(lastChild)), outlet, false);
|
segment, routes, newPaths.concat(paths.slice(lastChild)), outlet, false);
|
||||||
|
@ -94,7 +94,7 @@ import {Type} from '@angular/core';
|
|||||||
* '/team/11/user/jim', and then will instantiate the team component with the user component
|
* '/team/11/user/jim', and then will instantiate the team component with the user component
|
||||||
* in it.
|
* 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'.
|
* example above we change the `redirectTo` to `/user/:name`, the result url will be '/user/jim'.
|
||||||
*
|
*
|
||||||
* ### Empty Path
|
* ### Empty Path
|
||||||
|
@ -115,17 +115,17 @@ describe('applyRedirects', () => {
|
|||||||
'/a/1(aux:c/d)', (t: UrlTree) => { compareTrees(t, tree('/404')); });
|
'/a/1(aux:c/d)', (t: UrlTree) => { compareTrees(t, tree('/404')); });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support global redirects', () => {
|
it('should support absolute redirects', () => {
|
||||||
checkRedirect(
|
checkRedirect(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
path: 'a',
|
path: 'a',
|
||||||
component: ComponentA,
|
component: ComponentA,
|
||||||
children: [{path: 'b/:id', redirectTo: '/global/:id'}]
|
children: [{path: 'b/:id', redirectTo: '/absolute/:id'}]
|
||||||
},
|
},
|
||||||
{path: '**', component: ComponentC}
|
{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', () => {
|
describe('empty paths', () => {
|
||||||
@ -144,7 +144,7 @@ describe('applyRedirects', () => {
|
|||||||
'b', (t: UrlTree) => { compareTrees(t, tree('a/b')); });
|
'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(
|
checkRedirect(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user