mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
docs(docs-infra): ensure all redirections are absolute
fixes #64824
(cherry picked from commit 434ddbcfc9)
This commit is contained in:
parent
32a166bdb7
commit
dc99f4c55a
2 changed files with 36 additions and 3 deletions
31
adev/src/app/routing/redirections.spec.ts
Normal file
31
adev/src/app/routing/redirections.spec.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*!
|
||||
* @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 {REDIRECT_ROUTES} from './redirections';
|
||||
import {Route} from '@angular/router';
|
||||
|
||||
describe('REDIRECT_ROUTES', () => {
|
||||
it('should have all redirectTo values starting with a "/"', () => {
|
||||
const checkRoutes = (routes: Route[]) => {
|
||||
for (const route of routes) {
|
||||
if (route.redirectTo) {
|
||||
if (typeof route.redirectTo === 'string') {
|
||||
expect(route.redirectTo.startsWith('/'))
|
||||
.withContext(`Invalid redirectTo: ${route.redirectTo}`)
|
||||
.toBe(true);
|
||||
}
|
||||
}
|
||||
if (route.children) {
|
||||
checkRoutes(route.children);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
checkRoutes(REDIRECT_ROUTES);
|
||||
});
|
||||
});
|
||||
|
|
@ -10,20 +10,22 @@ import {Route} from '@angular/router';
|
|||
/**
|
||||
* This file contains the redirections we keep to prevent breakages on existing links
|
||||
* that may exist on the internet and over which we have no control.
|
||||
*
|
||||
* The redirectTo should always that start with a "/" to avoid relative redirections.
|
||||
*/
|
||||
|
||||
export const REDIRECT_ROUTES: Route[] = [
|
||||
{
|
||||
path: 'guide/di/dependency-injection',
|
||||
redirectTo: 'guide/di',
|
||||
redirectTo: '/guide/di',
|
||||
},
|
||||
{
|
||||
path: 'guide/di/creating-injectable-service',
|
||||
redirectTo: 'guide/di/creating-and-using-services',
|
||||
redirectTo: '/guide/di/creating-and-using-services',
|
||||
},
|
||||
{
|
||||
path: 'guide/di/dependency-injection-providers',
|
||||
redirectTo: 'guide/di/defining-dependency-providers',
|
||||
redirectTo: '/guide/di/defining-dependency-providers',
|
||||
},
|
||||
{
|
||||
path: 'guide/defer',
|
||||
|
|
|
|||
Loading…
Reference in a new issue