| 97 | } |
| 98 | |
| 99 | function externalRedirect(target: string | (() => string)): Partial<Route> { |
| 100 | // Typed explicitly, because `canActivate` also accepts deprecated class-based guards. Any function |
| 101 | // matches that type as well, so an inline guard wouldn't have its return value type checked. |
| 102 | const redirect: CanActivateFn = () => { |
| 103 | window.location.href = typeof target === 'string' ? target : target(); |
| 104 | return false; |
| 105 | }; |
| 106 | |
| 107 | return { |
| 108 | // The router requires a `component`. |
| 109 | component: RedirectPlaceholder, |
| 110 | canActivate: [redirect], |
| 111 | }; |
| 112 | } |