mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
docs: add example for conditional redirects in routing
This commit is contained in:
committed by
Jessica Janiuk
parent
544d084c34
commit
ea3097c774
@@ -38,6 +38,24 @@ Use `redirectTo` to point one path to another.
|
||||
{ path: 'blog', component: Blog },
|
||||
```
|
||||
|
||||
### Conditional Redirects
|
||||
|
||||
Pass a function to `redirectTo` to apply logic when redirecting.
|
||||
|
||||
```ts
|
||||
{
|
||||
path: 'restaurant/:location/menu',
|
||||
redirectTo: ({ params }) => {
|
||||
const base = `/restaurant/${params['location']}/menu`;
|
||||
const hour = new Date().getHours();
|
||||
|
||||
if (hour < 11) return `${base}/breakfast`;
|
||||
if (hour < 17) return `${base}/lunch`;
|
||||
return `${base}/dinner`;
|
||||
},
|
||||
},
|
||||
```
|
||||
|
||||
## Page Titles
|
||||
|
||||
Associate titles with routes for accessibility. Titles can be static or dynamic (via `ResolveFn` or a custom `TitleStrategy`).
|
||||
|
||||
Reference in New Issue
Block a user