2016-04-28 17:50:03 -07:00
|
|
|
import {Type} from '../src/facade/lang';
|
2016-02-09 11:12:41 -08:00
|
|
|
import {RegexSerializer} from './rules/route_paths/regex_route_path';
|
2015-07-13 16:12:48 -07:00
|
|
|
|
2015-09-21 14:43:24 -07:00
|
|
|
/**
|
|
|
|
* `RouteDefinition` defines a route within a {@link RouteConfig} decorator.
|
|
|
|
*
|
|
|
|
* Supported keys:
|
2015-10-30 17:05:30 -07:00
|
|
|
* - `path` or `aux` (requires exactly one of these)
|
2015-09-21 14:43:24 -07:00
|
|
|
* - `component`, `loader`, `redirectTo` (requires exactly one of these)
|
2016-03-19 20:08:25 +05:30
|
|
|
* - `name` (optional)
|
2015-09-21 14:43:24 -07:00
|
|
|
* - `data` (optional)
|
|
|
|
*
|
|
|
|
* See also {@link Route}, {@link AsyncRoute}, {@link AuxRoute}, and {@link Redirect}.
|
|
|
|
*/
|
2015-07-13 16:12:48 -07:00
|
|
|
export interface RouteDefinition {
|
2015-10-30 17:05:30 -07:00
|
|
|
path?: string;
|
|
|
|
aux?: string;
|
2016-02-09 11:12:41 -08:00
|
|
|
regex?: string;
|
2016-03-21 17:31:42 +01:00
|
|
|
regex_group_names?: string[];
|
2016-02-09 11:12:41 -08:00
|
|
|
serializer?: RegexSerializer;
|
2016-04-12 09:40:37 -07:00
|
|
|
component?: Type | ComponentDefinition;
|
2016-02-19 11:49:31 -08:00
|
|
|
loader?: () => Promise<Type>;
|
refactor(router): improve recognition and generation pipeline
This is a big change. @matsko also deserves much of the credit for the implementation.
Previously, `ComponentInstruction`s held all the state for async components.
Now, we introduce several subclasses for `Instruction` to describe each type of navigation.
BREAKING CHANGE:
Redirects now use the Link DSL syntax. Before:
```
@RouteConfig([
{ path: '/foo', redirectTo: '/bar' },
{ path: '/bar', component: BarCmp }
])
```
After:
```
@RouteConfig([
{ path: '/foo', redirectTo: ['Bar'] },
{ path: '/bar', component: BarCmp, name: 'Bar' }
])
```
BREAKING CHANGE:
This also introduces `useAsDefault` in the RouteConfig, which makes cases like lazy-loading
and encapsulating large routes with sub-routes easier.
Previously, you could use `redirectTo` like this to expand a URL like `/tab` to `/tab/posts`:
@RouteConfig([
{ path: '/tab', redirectTo: '/tab/users' }
{ path: '/tab', component: TabsCmp, name: 'Tab' }
])
AppCmp { ... }
Now the recommended way to handle this is case is to use `useAsDefault` like so:
```
@RouteConfig([
{ path: '/tab', component: TabsCmp, name: 'Tab' }
])
AppCmp { ... }
@RouteConfig([
{ path: '/posts', component: PostsCmp, useAsDefault: true, name: 'Posts' },
{ path: '/users', component: UsersCmp, name: 'Users' }
])
TabsCmp { ... }
```
In the above example, you can write just `['/Tab']` and the route `Users` is automatically selected as a child route.
Closes #4728
Closes #4228
Closes #4170
Closes #4490
Closes #4694
Closes #5200
Closes #5475
2015-11-23 18:07:37 -08:00
|
|
|
redirectTo?: any[];
|
2015-10-25 15:00:27 +05:30
|
|
|
name?: string;
|
2015-08-10 20:29:40 -04:00
|
|
|
data?: any;
|
refactor(router): improve recognition and generation pipeline
This is a big change. @matsko also deserves much of the credit for the implementation.
Previously, `ComponentInstruction`s held all the state for async components.
Now, we introduce several subclasses for `Instruction` to describe each type of navigation.
BREAKING CHANGE:
Redirects now use the Link DSL syntax. Before:
```
@RouteConfig([
{ path: '/foo', redirectTo: '/bar' },
{ path: '/bar', component: BarCmp }
])
```
After:
```
@RouteConfig([
{ path: '/foo', redirectTo: ['Bar'] },
{ path: '/bar', component: BarCmp, name: 'Bar' }
])
```
BREAKING CHANGE:
This also introduces `useAsDefault` in the RouteConfig, which makes cases like lazy-loading
and encapsulating large routes with sub-routes easier.
Previously, you could use `redirectTo` like this to expand a URL like `/tab` to `/tab/posts`:
@RouteConfig([
{ path: '/tab', redirectTo: '/tab/users' }
{ path: '/tab', component: TabsCmp, name: 'Tab' }
])
AppCmp { ... }
Now the recommended way to handle this is case is to use `useAsDefault` like so:
```
@RouteConfig([
{ path: '/tab', component: TabsCmp, name: 'Tab' }
])
AppCmp { ... }
@RouteConfig([
{ path: '/posts', component: PostsCmp, useAsDefault: true, name: 'Posts' },
{ path: '/users', component: UsersCmp, name: 'Users' }
])
TabsCmp { ... }
```
In the above example, you can write just `['/Tab']` and the route `Users` is automatically selected as a child route.
Closes #4728
Closes #4228
Closes #4170
Closes #4490
Closes #4694
Closes #5200
Closes #5475
2015-11-23 18:07:37 -08:00
|
|
|
useAsDefault?: boolean;
|
2015-07-13 16:12:48 -07:00
|
|
|
}
|
|
|
|
|
2015-12-03 15:49:09 -08:00
|
|
|
/**
|
|
|
|
* Represents either a component type (`type` is `component`) or a loader function
|
|
|
|
* (`type` is `loader`).
|
|
|
|
*
|
|
|
|
* See also {@link RouteDefinition}.
|
|
|
|
*/
|
2015-07-13 16:12:48 -07:00
|
|
|
export interface ComponentDefinition {
|
|
|
|
type: string;
|
2016-02-19 11:49:31 -08:00
|
|
|
loader?: () => Promise<Type>;
|
2015-07-13 16:12:48 -07:00
|
|
|
component?: Type;
|
|
|
|
}
|