| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | } from '@angular/core/testing/testing_internal'; | 
					
						
							|  |  |  | import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-04-17 09:59:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {PromiseWrapper} from '../src/facade/async'; | 
					
						
							|  |  |  | import {Type, IS_DART} from '../src/facade/lang'; | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 10:36:58 -07:00
										 |  |  | import {RouteRegistry} from '../src/route_registry'; | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   RouteConfig, | 
					
						
							|  |  |  |   Route, | 
					
						
							|  |  |  |   Redirect, | 
					
						
							|  |  |  |   AuxRoute, | 
					
						
							|  |  |  |   AsyncRoute | 
					
						
							| 
									
										
										
										
											2016-05-02 10:36:58 -07:00
										 |  |  | } from '../src/route_config/route_config_decorator'; | 
					
						
							| 
									
										
											  
											
												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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-17 09:59:56 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('RouteRegistry', () => { | 
					
						
							| 
									
										
										
										
											2016-02-19 11:49:31 -08:00
										 |  |  |     var registry: RouteRegistry; | 
					
						
							| 
									
										
										
										
											2015-04-17 09:59:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |     beforeEach(() => { registry = new RouteRegistry(RootHostCmp); }); | 
					
						
							| 
									
										
										
										
											2015-04-17 09:59:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  |     it('should match the full URL', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |          registry.config(RootHostCmp, new Route({path: '/', component: DummyCmpA})); | 
					
						
							|  |  |  |          registry.config(RootHostCmp, new Route({path: '/test', component: DummyCmpB})); | 
					
						
							| 
									
										
										
										
											2015-04-17 09:59:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.recognize('/test', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyCmpB); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-04-17 09:59:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  |     it('should generate URLs starting at the given component', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       registry.config(RootHostCmp, | 
					
						
							|  |  |  |                       new Route({path: '/first/...', component: DummyParentCmp, name: 'FirstCmp'})); | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |       var instr = registry.generate(['FirstCmp', 'SecondCmp'], []); | 
					
						
							|  |  |  |       expect(stringifyInstruction(instr)).toEqual('first/second'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 10:51:01 -08:00
										 |  |  |       expect(stringifyInstruction(registry.generate(['SecondCmp'], [instr, instr.child]))) | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |           .toEqual('first/second'); | 
					
						
							| 
									
										
										
										
											2015-12-07 10:51:01 -08:00
										 |  |  |       expect(stringifyInstruction(registry.generate(['./SecondCmp'], [instr, instr.child]))) | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  |           .toEqual('first/second'); | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |     it('should generate URLs that account for default routes', () => { | 
					
						
							| 
									
										
										
										
											2015-08-13 11:09:22 -07:00
										 |  |  |       registry.config( | 
					
						
							|  |  |  |           RootHostCmp, | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |           new Route({path: '/first/...', component: ParentWithDefaultRouteCmp, name: 'FirstCmp'})); | 
					
						
							| 
									
										
											  
											
												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 #4170
Closes #4490
Closes #4694
Closes #5200
Closes #5352
											
										 
											2015-11-02 16:14:10 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |       var instruction = registry.generate(['FirstCmp'], []); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(instruction.toLinkUrl()).toEqual('first'); | 
					
						
							|  |  |  |       expect(instruction.toRootUrl()).toEqual('first/second'); | 
					
						
							| 
									
										
										
										
											2015-08-13 11:09:22 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |     it('should generate URLs in a hierarchy of default routes', () => { | 
					
						
							| 
									
										
										
										
											2015-08-13 11:09:22 -07:00
										 |  |  |       registry.config( | 
					
						
							|  |  |  |           RootHostCmp, | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |           new Route({path: '/first/...', component: MultipleDefaultCmp, name: 'FirstCmp'})); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       var instruction = registry.generate(['FirstCmp'], []); | 
					
						
							| 
									
										
										
										
											2015-08-13 11:09:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |       expect(instruction.toLinkUrl()).toEqual('first'); | 
					
						
							|  |  |  |       expect(instruction.toRootUrl()).toEqual('first/second/third'); | 
					
						
							| 
									
										
										
										
											2015-08-13 11:09:22 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  |     it('should generate URLs with params', () => { | 
					
						
							|  |  |  |       registry.config( | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  |           RootHostCmp, | 
					
						
							| 
									
										
										
										
											2015-10-25 15:00:27 +05:30
										 |  |  |           new Route({path: '/first/:param/...', component: DummyParentParamCmp, name: 'FirstCmp'})); | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |       var url = stringifyInstruction( | 
					
						
							|  |  |  |           registry.generate(['FirstCmp', {param: 'one'}, 'SecondCmp', {param: 'two'}], [])); | 
					
						
							| 
									
										
										
										
											2015-07-06 17:41:15 -07:00
										 |  |  |       expect(url).toEqual('first/one/second/two'); | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-09 07:49:02 -07:00
										 |  |  |     it('should generate params as an empty StringMap when no params are given', () => { | 
					
						
							| 
									
										
										
										
											2015-10-25 15:00:27 +05:30
										 |  |  |       registry.config(RootHostCmp, new Route({path: '/test', component: DummyCmpA, name: 'Test'})); | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |       var instruction = registry.generate(['Test'], []); | 
					
						
							| 
									
										
										
										
											2015-08-25 11:59:57 -04:00
										 |  |  |       expect(instruction.component.params).toEqual({}); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 14:24:48 +00:00
										 |  |  |     it('should generate URLs with extra params in the query', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       registry.config(RootHostCmp, | 
					
						
							|  |  |  |                       new Route({path: '/first/second', component: DummyCmpA, name: 'FirstCmp'})); | 
					
						
							| 
									
										
										
										
											2016-03-04 14:24:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       var instruction = registry.generate(['FirstCmp', {a: 'one'}], []); | 
					
						
							|  |  |  |       expect(instruction.toLinkUrl()).toEqual('first/second?a=one'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  |     it('should generate URLs of loaded components after they are loaded', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |          registry.config( | 
					
						
							|  |  |  |              RootHostCmp, | 
					
						
							| 
									
										
										
										
											2015-11-23 18:07:10 -08:00
										 |  |  |              new AsyncRoute({path: '/first/...', loader: asyncParentLoader, name: 'FirstCmp'})); | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |          var instruction = registry.generate(['FirstCmp', 'SecondCmp'], []); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          expect(stringifyInstruction(instruction)).toEqual('first'); | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.recognize('/first/second', []) | 
					
						
							|  |  |  |              .then((_) => { | 
					
						
							|  |  |  |                var instruction = registry.generate(['FirstCmp', 'SecondCmp'], []); | 
					
						
							|  |  |  |                expect(stringifyInstruction(instruction)).toEqual('first/second'); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  |     it('should throw when generating a url and a parent has no config', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       expect(() => registry.generate(['FirstCmp', 'SecondCmp'], [])) | 
					
						
							|  |  |  |           .toThrowError('Component "RootHostCmp" has no route config.'); | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 18:07:10 -08:00
										 |  |  |     it('should generate URLs for aux routes', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       registry.config(RootHostCmp, | 
					
						
							|  |  |  |                       new Route({path: '/primary', component: DummyCmpA, name: 'Primary'})); | 
					
						
							| 
									
										
										
										
											2015-11-23 18:07:10 -08:00
										 |  |  |       registry.config(RootHostCmp, new AuxRoute({path: '/aux', component: DummyCmpB, name: 'Aux'})); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       expect(stringifyInstruction(registry.generate(['Primary', ['Aux']], []))) | 
					
						
							|  |  |  |           .toEqual('primary(aux)'); | 
					
						
							| 
									
										
										
										
											2015-11-23 18:07:10 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  |     it('should prefer static segments to dynamic', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |          registry.config(RootHostCmp, new Route({path: '/:site', component: DummyCmpB})); | 
					
						
							|  |  |  |          registry.config(RootHostCmp, new Route({path: '/home', component: DummyCmpA})); | 
					
						
							| 
									
										
										
										
											2015-05-12 14:53:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.recognize('/home', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyCmpA); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-05-12 14:53:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  |     it('should prefer dynamic segments to star', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |          registry.config(RootHostCmp, new Route({path: '/:site', component: DummyCmpA})); | 
					
						
							|  |  |  |          registry.config(RootHostCmp, new Route({path: '/*site', component: DummyCmpB})); | 
					
						
							| 
									
										
										
										
											2015-05-12 14:53:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.recognize('/home', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyCmpA); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-05-12 14:53:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  |     it('should prefer routes with more dynamic segments', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |          registry.config(RootHostCmp, new Route({path: '/:first/*rest', component: DummyCmpA})); | 
					
						
							|  |  |  |          registry.config(RootHostCmp, new Route({path: '/*all', component: DummyCmpB})); | 
					
						
							| 
									
										
										
										
											2015-05-15 02:05:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.recognize('/some/path', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyCmpA); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-05-15 02:05:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  |     it('should prefer routes with more static segments', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |          registry.config(RootHostCmp, new Route({path: '/first/:second', component: DummyCmpA})); | 
					
						
							|  |  |  |          registry.config(RootHostCmp, new Route({path: '/:first/:second', component: DummyCmpB})); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.recognize('/first/second', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyCmpA); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should prefer routes with static segments before dynamic segments', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.config(RootHostCmp, | 
					
						
							|  |  |  |                          new Route({path: '/first/second/:third', component: DummyCmpB})); | 
					
						
							|  |  |  |          registry.config(RootHostCmp, | 
					
						
							|  |  |  |                          new Route({path: '/first/:second/third', component: DummyCmpA})); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          registry.recognize('/first/second/third', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyCmpB); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-05-15 02:05:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-18 10:05:55 -08:00
										 |  |  |     it('should prefer routes with high specificity over routes with children with lower specificity', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |          registry.config(RootHostCmp, new Route({path: '/first', component: DummyCmpA})); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          // terminates to DummyCmpB
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.config(RootHostCmp, | 
					
						
							|  |  |  |                          new Route({path: '/:second/...', component: SingleSlashChildCmp})); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          registry.recognize('/first', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyCmpA); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-12-18 10:05:55 -08:00
										 |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  |     it('should match the full URL using child components', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |          registry.config(RootHostCmp, new Route({path: '/first/...', component: DummyParentCmp})); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.recognize('/first/second', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyParentCmp); | 
					
						
							|  |  |  |                expect(instruction.child.component.componentType).toBe(DummyCmpB); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should match the URL using async child components', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  |          registry.config(RootHostCmp, new Route({path: '/first/...', component: DummyAsyncCmp})); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.recognize('/first/second', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyAsyncCmp); | 
					
						
							| 
									
										
											  
											
												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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |                instruction.child.resolveComponent().then((childComponentInstruction) => { | 
					
						
							|  |  |  |                  expect(childComponentInstruction.componentType).toBe(DummyCmpB); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should match the URL using an async parent component', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.config(RootHostCmp, | 
					
						
							|  |  |  |                          new AsyncRoute({path: '/first/...', loader: asyncParentLoader})); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          registry.recognize('/first/second', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyParentCmp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                instruction.child.resolveComponent().then((childType) => { | 
					
						
							|  |  |  |                  expect(childType.componentType).toBe(DummyCmpB); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-17 11:57:38 -07:00
										 |  |  |     it('should throw when a parent config is missing the `...` suffix any of its children add routes', | 
					
						
							|  |  |  |        () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          expect(() => | 
					
						
							|  |  |  |                     registry.config(RootHostCmp, new Route({path: '/', component: DummyParentCmp}))) | 
					
						
							| 
									
										
										
										
											2015-06-17 11:57:38 -07:00
										 |  |  |              .toThrowError( | 
					
						
							|  |  |  |                  'Child routes are not allowed for "/". Use "..." on the parent\'s route path.'); | 
					
						
							|  |  |  |        }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  |     it('should throw when a parent config uses `...` suffix before the end of the route', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       expect(() => registry.config(RootHostCmp, | 
					
						
							|  |  |  |                                    new Route({path: '/home/.../fun/', component: DummyParentCmp}))) | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  |           .toThrowError('Unexpected "..." before the end of the path for "home/.../fun/".'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-07-13 16:12:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 13:05:08 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should throw if a config has a component that is not defined', () => { | 
					
						
							|  |  |  |       expect(() => registry.config(RootHostCmp, new Route({path: '/', component: null}))) | 
					
						
							|  |  |  |           .toThrowError('Component for route "/" is not defined, or is not a class.'); | 
					
						
							|  |  |  |       expect(() => registry.config(RootHostCmp, new AuxRoute({path: '/', component: null}))) | 
					
						
							|  |  |  |           .toThrowError('Component for route "/" is not defined, or is not a class.'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // This would never happen in Dart
 | 
					
						
							| 
									
										
										
										
											2015-08-11 14:00:54 -07:00
										 |  |  |       if (!IS_DART) { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |         expect(() => registry.config(RootHostCmp, new Route({path: '/', component:<Type>(<any>4)}))) | 
					
						
							| 
									
										
										
										
											2015-08-10 13:05:08 -07:00
										 |  |  |             .toThrowError('Component for route "/" is not defined, or is not a class.'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-09 07:49:02 -07:00
										 |  |  |     it('should throw when linkParams are not terminal', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       registry.config(RootHostCmp, | 
					
						
							|  |  |  |                       new Route({path: '/first/...', component: DummyParentCmp, name: 'First'})); | 
					
						
							|  |  |  |       expect(() => { registry.generate(['First'], []); }) | 
					
						
							|  |  |  |           .toThrowError('Link "["First"]" does not resolve to a terminal instruction.'); | 
					
						
							| 
									
										
										
										
											2015-09-09 07:49:02 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  |     it('should match matrix params on child components and query params on the root component', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |          registry.config(RootHostCmp, new Route({path: '/first/...', component: DummyParentCmp})); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          registry.recognize('/first/second;filter=odd?comments=all', []) | 
					
						
							|  |  |  |              .then((instruction) => { | 
					
						
							|  |  |  |                expect(instruction.component.componentType).toBe(DummyParentCmp); | 
					
						
							|  |  |  |                expect(instruction.component.params).toEqual({'comments': 'all'}); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |                expect(instruction.child.component.componentType).toBe(DummyCmpB); | 
					
						
							|  |  |  |                expect(instruction.child.component.params).toEqual({'filter': 'odd'}); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should generate URLs with matrix and query params', () => { | 
					
						
							|  |  |  |       registry.config( | 
					
						
							|  |  |  |           RootHostCmp, | 
					
						
							| 
									
										
										
										
											2015-10-25 15:00:27 +05:30
										 |  |  |           new Route({path: '/first/:param/...', component: DummyParentParamCmp, name: 'FirstCmp'})); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       var url = stringifyInstruction(registry.generate( | 
					
						
							|  |  |  |           [ | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |             'FirstCmp', | 
					
						
							|  |  |  |             {param: 'one', query: 'cats'}, | 
					
						
							|  |  |  |             'SecondCmp', | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  |               param: 'two', | 
					
						
							|  |  |  |               sort: 'asc', | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           ], | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |           [])); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:36:53 -07:00
										 |  |  |       expect(url).toEqual('first/one/second/two;sort=asc?query=cats'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-17 09:59:56 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-04-29 15:47:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  | function stringifyInstruction(instruction): string { | 
					
						
							|  |  |  |   return instruction.toRootUrl(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 18:07:10 -08:00
										 |  |  | function asyncParentLoader() { | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  |   return PromiseWrapper.resolve(DummyParentCmp); | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 18:07:10 -08:00
										 |  |  | function asyncChildLoader() { | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  |   return PromiseWrapper.resolve(DummyCmpB); | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  | class RootHostCmp {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 18:07:10 -08:00
										 |  |  | @RouteConfig([new AsyncRoute({path: '/second', loader: asyncChildLoader})]) | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  | class DummyAsyncCmp { | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-05-21 13:59:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  | class DummyCmpA {} | 
					
						
							|  |  |  | class DummyCmpB {} | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  | @RouteConfig( | 
					
						
							|  |  |  |     [new Route({path: '/third', component: DummyCmpB, name: 'ThirdCmp', useAsDefault: true})]) | 
					
						
							|  |  |  | class DefaultRouteCmp { | 
					
						
							| 
									
										
										
										
											2015-08-13 11:09:22 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-18 10:05:55 -08:00
										 |  |  | @RouteConfig([new Route({path: '/', component: DummyCmpB, name: 'ThirdCmp'})]) | 
					
						
							|  |  |  | class SingleSlashChildCmp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-13 11:09:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  | @RouteConfig([ | 
					
						
							|  |  |  |   new Route( | 
					
						
							|  |  |  |       {path: '/second/...', component: DefaultRouteCmp, name: 'SecondCmp', useAsDefault: true}) | 
					
						
							|  |  |  | ]) | 
					
						
							| 
									
										
											  
											
												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
										 |  |  | class MultipleDefaultCmp { | 
					
						
							| 
									
										
										
										
											2015-08-13 11:09:22 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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
										 |  |  | @RouteConfig( | 
					
						
							|  |  |  |     [new Route({path: '/second', component: DummyCmpB, name: 'SecondCmp', useAsDefault: true})]) | 
					
						
							|  |  |  | class ParentWithDefaultRouteCmp { | 
					
						
							| 
									
										
										
										
											2015-08-13 11:09:22 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-25 15:00:27 +05:30
										 |  |  | @RouteConfig([new Route({path: '/second', component: DummyCmpB, name: 'SecondCmp'})]) | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  | class DummyParentCmp { | 
					
						
							| 
									
										
										
										
											2015-05-29 14:58:41 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-25 15:00:27 +05:30
										 |  |  | @RouteConfig([new Route({path: '/second/:param', component: DummyCmpB, name: 'SecondCmp'})]) | 
					
						
							| 
									
										
										
										
											2015-07-13 15:29:14 -07:00
										 |  |  | class DummyParentParamCmp { | 
					
						
							| 
									
										
										
										
											2015-06-30 13:18:51 -07:00
										 |  |  | } |