2015-05-29 17:58:41 -04:00
|
|
|
import {
|
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
2015-11-06 13:01:03 -05:00
|
|
|
beforeEachProviders,
|
2015-05-29 17:58:41 -04:00
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
expect,
|
|
|
|
iit,
|
2015-07-21 04:26:43 -04:00
|
|
|
flushMicrotasks,
|
2015-05-29 17:58:41 -04:00
|
|
|
inject,
|
|
|
|
it,
|
|
|
|
xdescribe,
|
2015-07-21 18:05:08 -04:00
|
|
|
TestComponentBuilder,
|
2015-05-29 17:58:41 -04:00
|
|
|
xit,
|
2015-10-13 03:29:13 -04:00
|
|
|
} from 'angular2/testing_internal';
|
2015-05-29 17:58:41 -04:00
|
|
|
|
2015-11-23 13:18:04 -05:00
|
|
|
import {bootstrap} from 'angular2/platform/browser';
|
2015-09-04 01:01:36 -04:00
|
|
|
import {Component, Directive, View} from 'angular2/src/core/metadata';
|
2015-11-19 18:09:34 -05:00
|
|
|
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
2015-11-06 13:01:03 -05:00
|
|
|
import {provide, ViewChild, AfterViewInit} from 'angular2/core';
|
2015-11-17 18:24:36 -05:00
|
|
|
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
|
2015-11-06 13:01:03 -05:00
|
|
|
import {RouteConfig, Route, Redirect, AuxRoute} from 'angular2/src/router/route_config_decorator';
|
2015-11-06 20:34:07 -05:00
|
|
|
import {PromiseWrapper} from 'angular2/src/facade/async';
|
|
|
|
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
|
2015-07-21 04:26:43 -04:00
|
|
|
import {
|
2015-10-11 01:11:13 -04:00
|
|
|
ROUTER_PROVIDERS,
|
2015-09-03 15:55:08 -04:00
|
|
|
ROUTER_PRIMARY_COMPONENT,
|
2015-07-21 04:26:43 -04:00
|
|
|
RouteParams,
|
|
|
|
Router,
|
2015-08-11 00:42:47 -04:00
|
|
|
APP_BASE_HREF,
|
2015-08-18 17:46:35 -04:00
|
|
|
ROUTER_DIRECTIVES,
|
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 21:07:37 -05:00
|
|
|
LocationStrategy
|
2015-07-21 04:26:43 -04:00
|
|
|
} from 'angular2/router';
|
|
|
|
|
2015-06-22 15:14:19 -04:00
|
|
|
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
|
2015-10-26 14:01:02 -04:00
|
|
|
import {ApplicationRef} from 'angular2/src/core/application_ref';
|
|
|
|
import {MockApplicationRef} from 'angular2/src/mock/mock_application_ref';
|
2015-05-29 17:58:41 -04:00
|
|
|
|
|
|
|
export function main() {
|
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 21:07:37 -05:00
|
|
|
describe('router bootstrap', () => {
|
|
|
|
beforeEachProviders(() => [
|
|
|
|
ROUTER_PROVIDERS,
|
|
|
|
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
|
|
|
provide(ApplicationRef, {useClass: MockApplicationRef})
|
|
|
|
]);
|
2015-05-29 17:58:41 -04:00
|
|
|
|
2015-07-21 18:05:08 -04:00
|
|
|
// do not refactor out the `bootstrap` functionality. We still want to
|
|
|
|
// keep this test around so we can ensure that bootstrapping a router works
|
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 21:07:37 -05:00
|
|
|
it('should bootstrap a simple app', inject([AsyncTestCompleter], (async) => {
|
|
|
|
var fakeDoc = DOM.createHtmlDocument();
|
|
|
|
var el = DOM.createElement('app-cmp', fakeDoc);
|
|
|
|
DOM.appendChild(fakeDoc.body, el);
|
|
|
|
|
|
|
|
bootstrap(AppCmp,
|
|
|
|
[
|
|
|
|
ROUTER_PROVIDERS,
|
|
|
|
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
|
|
|
|
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
|
|
|
provide(DOCUMENT, {useValue: fakeDoc})
|
|
|
|
])
|
|
|
|
.then((applicationRef) => {
|
|
|
|
var router = applicationRef.hostComponent.router;
|
|
|
|
router.subscribe((_) => {
|
|
|
|
expect(el).toHaveText('outer { hello }');
|
|
|
|
expect(applicationRef.hostComponent.location.path()).toEqual('');
|
|
|
|
async.done();
|
2015-06-08 21:04:13 -04: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 21:07:37 -05:00
|
|
|
});
|
|
|
|
}));
|
2015-06-08 21:04:13 -04:00
|
|
|
|
2015-07-21 18:05:08 -04:00
|
|
|
describe('broken app', () => {
|
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 21:07:37 -05:00
|
|
|
beforeEachProviders(() => [provide(ROUTER_PRIMARY_COMPONENT, {useValue: BrokenAppCmp})]);
|
2015-07-21 18:05:08 -04:00
|
|
|
|
|
|
|
it('should rethrow exceptions from component constructors',
|
|
|
|
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
tcb.createAsync(AppCmp).then((fixture) => {
|
|
|
|
var router = fixture.debugElement.componentInstance.router;
|
2015-09-09 00:41:56 -04:00
|
|
|
PromiseWrapper.catchError(router.navigateByUrl('/cause-error'), (error) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('outer { oh no }');
|
2015-07-23 21:00:19 -04:00
|
|
|
expect(error).toContainError('oops!');
|
2015-07-21 18:05:08 -04:00
|
|
|
async.done();
|
2015-06-15 18:41:09 -04:00
|
|
|
});
|
2015-07-21 18:05:08 -04:00
|
|
|
});
|
2015-09-09 10:41:11 -04:00
|
|
|
}));
|
2015-07-21 18:05:08 -04:00
|
|
|
});
|
2015-06-15 18:41:09 -04:00
|
|
|
|
2015-07-28 01:46:09 -04:00
|
|
|
describe('back button app', () => {
|
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 21:07:37 -05:00
|
|
|
beforeEachProviders(() => [provide(ROUTER_PRIMARY_COMPONENT, {useValue: HierarchyAppCmp})]);
|
2015-07-28 01:46:09 -04:00
|
|
|
|
|
|
|
it('should change the url without pushing a new history state for back navigations',
|
|
|
|
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
|
|
|
|
|
|
|
tcb.createAsync(HierarchyAppCmp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
var router = fixture.debugElement.componentInstance.router;
|
2015-07-28 01:46:09 -04:00
|
|
|
var position = 0;
|
|
|
|
var flipped = false;
|
2015-11-06 13:01:03 -05:00
|
|
|
var history = [
|
|
|
|
['/parent/child', 'root { parent { hello } }', '/super-parent/child'],
|
|
|
|
['/super-parent/child', 'root { super-parent { hello2 } }', '/parent/child'],
|
|
|
|
['/parent/child', 'root { parent { hello } }', false]
|
|
|
|
];
|
|
|
|
|
|
|
|
router.subscribe((_) => {
|
|
|
|
var location = fixture.debugElement.componentInstance.location;
|
|
|
|
var element = fixture.debugElement.nativeElement;
|
|
|
|
var path = location.path();
|
|
|
|
|
|
|
|
var entry = history[position];
|
|
|
|
|
|
|
|
expect(path).toEqual(entry[0]);
|
|
|
|
expect(element).toHaveText(entry[1]);
|
|
|
|
|
|
|
|
var nextUrl = entry[2];
|
|
|
|
if (nextUrl == false) {
|
|
|
|
flipped = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flipped && position == 0) {
|
|
|
|
async.done();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
position = position + (flipped ? -1 : 1);
|
|
|
|
if (flipped) {
|
|
|
|
location.back();
|
|
|
|
} else {
|
|
|
|
router.navigateByUrl(nextUrl);
|
|
|
|
}
|
|
|
|
});
|
2015-07-28 01:46:09 -04:00
|
|
|
|
2015-09-09 00:41:56 -04:00
|
|
|
router.navigateByUrl(history[0][0]);
|
2015-07-28 01:46:09 -04:00
|
|
|
});
|
2015-08-12 20:53:08 -04:00
|
|
|
}), 1000);
|
2015-07-28 01:46:09 -04:00
|
|
|
});
|
|
|
|
|
2015-07-21 18:05:08 -04:00
|
|
|
describe('hierarchical app', () => {
|
2015-11-06 13:01:03 -05:00
|
|
|
beforeEachProviders(
|
2015-10-12 14:30:34 -04:00
|
|
|
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: HierarchyAppCmp})]; });
|
2015-07-21 18:05:08 -04:00
|
|
|
|
|
|
|
it('should bootstrap an app with a hierarchy',
|
|
|
|
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
|
|
|
|
|
|
|
tcb.createAsync(HierarchyAppCmp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
var router = fixture.debugElement.componentInstance.router;
|
2015-07-21 18:05:08 -04:00
|
|
|
router.subscribe((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
expect(fixture.debugElement.nativeElement)
|
2015-09-11 16:45:31 -04:00
|
|
|
.toHaveText('root { parent { hello } }');
|
2015-10-31 12:50:19 -04:00
|
|
|
expect(fixture.debugElement.componentInstance.location.path())
|
2015-09-11 16:45:31 -04:00
|
|
|
.toEqual('/parent/child');
|
2015-07-21 18:05:08 -04:00
|
|
|
async.done();
|
|
|
|
});
|
2015-09-09 00:41:56 -04:00
|
|
|
router.navigateByUrl('/parent/child');
|
2015-06-15 18:41:09 -04:00
|
|
|
});
|
2015-09-09 10:41:11 -04:00
|
|
|
}));
|
2015-07-21 18:05:08 -04:00
|
|
|
|
2015-10-26 09:57:41 -04:00
|
|
|
// TODO(btford): mock out level lower than LocationStrategy once that level exists
|
|
|
|
xdescribe('custom app base ref', () => {
|
2015-11-06 13:01:03 -05:00
|
|
|
beforeEachProviders(() => { return [provide(APP_BASE_HREF, {useValue: '/my/app'})]; });
|
2015-08-26 10:45:03 -04:00
|
|
|
it('should bootstrap',
|
|
|
|
inject([AsyncTestCompleter, TestComponentBuilder],
|
|
|
|
(async, tcb: TestComponentBuilder) => {
|
|
|
|
|
|
|
|
tcb.createAsync(HierarchyAppCmp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
var router = fixture.debugElement.componentInstance.router;
|
2015-08-26 10:45:03 -04:00
|
|
|
router.subscribe((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
expect(fixture.debugElement.nativeElement)
|
2015-09-11 16:45:31 -04:00
|
|
|
.toHaveText('root { parent { hello } }');
|
2015-10-31 12:50:19 -04:00
|
|
|
expect(fixture.debugElement.componentInstance.location.path())
|
2015-08-26 10:45:03 -04:00
|
|
|
.toEqual('/my/app/parent/child');
|
|
|
|
async.done();
|
|
|
|
});
|
2015-09-09 00:41:56 -04:00
|
|
|
router.navigateByUrl('/parent/child');
|
2015-08-26 10:45:03 -04:00
|
|
|
});
|
2015-09-09 10:41:11 -04:00
|
|
|
}));
|
2015-07-21 18:05:08 -04: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 21:07:37 -05:00
|
|
|
|
2015-07-21 04:26:43 -04:00
|
|
|
|
|
|
|
describe('querystring params app', () => {
|
2015-11-06 13:01:03 -05:00
|
|
|
beforeEachProviders(
|
2015-10-12 14:30:34 -04:00
|
|
|
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: QueryStringAppCmp})]; });
|
2015-07-21 04:26:43 -04:00
|
|
|
|
|
|
|
it('should recognize and return querystring params with the injected RouteParams',
|
|
|
|
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
|
|
|
tcb.createAsync(QueryStringAppCmp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
var router = fixture.debugElement.componentInstance.router;
|
2015-07-21 04:26:43 -04:00
|
|
|
router.subscribe((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
2015-07-21 04:26:43 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
expect(fixture.debugElement.nativeElement)
|
2015-09-11 16:45:31 -04:00
|
|
|
.toHaveText('qParam = search-for-something');
|
2015-07-21 04:26:43 -04:00
|
|
|
/*
|
|
|
|
expect(applicationRef.hostComponent.location.path())
|
|
|
|
.toEqual('/qs?q=search-for-something');*/
|
|
|
|
async.done();
|
|
|
|
});
|
2015-09-09 00:41:56 -04:00
|
|
|
router.navigateByUrl('/qs?q=search-for-something');
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
2015-07-21 04:26:43 -04:00
|
|
|
});
|
2015-09-09 10:41:11 -04:00
|
|
|
}));
|
2015-07-21 04:26:43 -04:00
|
|
|
});
|
2015-11-06 13:01:03 -05:00
|
|
|
|
|
|
|
describe('retrieving components loaded via outlet via @ViewChild', () => {
|
|
|
|
let tcb: TestComponentBuilder = null;
|
|
|
|
|
|
|
|
beforeEachProviders(() => [provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp})]);
|
|
|
|
|
|
|
|
beforeEach(inject([TestComponentBuilder],
|
|
|
|
(testComponentBuilder) => { tcb = testComponentBuilder; }));
|
|
|
|
|
|
|
|
it('should get a reference and pass data to components loaded inside of outlets',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
tcb.createAsync(AppWithViewChildren)
|
|
|
|
.then(fixture => {
|
|
|
|
let appInstance = fixture.debugElement.componentInstance;
|
|
|
|
let router = appInstance.router;
|
|
|
|
|
|
|
|
router.subscribe((_) => {
|
|
|
|
fixture.detectChanges();
|
|
|
|
|
|
|
|
expect(appInstance.helloCmp).toBeAnInstanceOf(HelloCmp);
|
|
|
|
expect(appInstance.helloCmp.message).toBe('Ahoy');
|
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
|
|
|
|
router.navigateByUrl('/rainbow(pony)');
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
2015-05-29 17:58:41 -04: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 21:07:37 -05:00
|
|
|
@Component({selector: 'hello-cmp', template: 'hello'})
|
2015-05-29 17:58:41 -04:00
|
|
|
class HelloCmp {
|
2015-11-06 13:01:03 -05:00
|
|
|
public message: string;
|
2015-05-29 17:58:41 -04: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 21:07:37 -05:00
|
|
|
@Component({selector: 'hello2-cmp', template: 'hello2'})
|
2015-07-28 01:46:09 -04:00
|
|
|
class Hello2Cmp {
|
2015-11-06 13:01:03 -05:00
|
|
|
public greeting: string;
|
2015-07-28 01:46:09 -04: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 21:07:37 -05:00
|
|
|
@Component({
|
|
|
|
selector: 'app-cmp',
|
|
|
|
template: `outer { <router-outlet></router-outlet> }`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
2015-07-13 19:12:48 -04:00
|
|
|
@RouteConfig([new Route({path: '/', component: HelloCmp})])
|
2015-05-29 17:58:41 -04:00
|
|
|
class AppCmp {
|
2015-06-22 15:14:19 -04:00
|
|
|
constructor(public router: Router, public location: LocationStrategy) {}
|
2015-06-15 18:41:09 -04:00
|
|
|
}
|
|
|
|
|
2015-11-06 13:01:03 -05:00
|
|
|
@Component({
|
|
|
|
selector: 'app-cmp',
|
|
|
|
template: `
|
|
|
|
Hello routing!
|
|
|
|
<router-outlet></router-outlet>
|
|
|
|
<router-outlet name="pony"></router-outlet>`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
|
|
|
@RouteConfig([
|
|
|
|
new Route({path: '/rainbow', component: HelloCmp}),
|
|
|
|
new AuxRoute({name: 'pony', path: 'pony', component: Hello2Cmp})
|
|
|
|
])
|
|
|
|
class AppWithViewChildren implements AfterViewInit {
|
|
|
|
@ViewChild(HelloCmp) helloCmp: HelloCmp;
|
|
|
|
@ViewChild(Hello2Cmp) hello2Cmp: Hello2Cmp;
|
|
|
|
|
|
|
|
constructor(public router: Router, public location: LocationStrategy) {}
|
|
|
|
|
refactor(lifecycle): prefix lifecycle methods with "ng"
BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.
To fix, just rename these methods:
* onInit
* onDestroy
* doCheck
* onChanges
* afterContentInit
* afterContentChecked
* afterViewInit
* afterViewChecked
* _Router Hooks_
* onActivate
* onReuse
* onDeactivate
* canReuse
* canDeactivate
To:
* ngOnInit,
* ngOnDestroy,
* ngDoCheck,
* ngOnChanges,
* ngAfterContentInit,
* ngAfterContentChecked,
* ngAfterViewInit,
* ngAfterViewChecked
* _Router Hooks_
* routerOnActivate
* routerOnReuse
* routerOnDeactivate
* routerCanReuse
* routerCanDeactivate
The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.
Closes #5036
2015-11-16 20:04:36 -05:00
|
|
|
ngAfterViewInit() { this.helloCmp.message = 'Ahoy'; }
|
2015-11-06 13:01:03 -05: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 21:07:37 -05:00
|
|
|
@Component({
|
|
|
|
selector: 'parent-cmp',
|
|
|
|
template: `parent { <router-outlet></router-outlet> }`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
2015-07-13 19:12:48 -04:00
|
|
|
@RouteConfig([new Route({path: '/child', component: HelloCmp})])
|
2015-06-15 18:41:09 -04:00
|
|
|
class ParentCmp {
|
|
|
|
}
|
|
|
|
|
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 21:07:37 -05:00
|
|
|
@Component({
|
|
|
|
selector: 'super-parent-cmp',
|
|
|
|
template: `super-parent { <router-outlet></router-outlet> }`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
2015-07-28 01:46:09 -04:00
|
|
|
@RouteConfig([new Route({path: '/child', component: Hello2Cmp})])
|
|
|
|
class SuperParentCmp {
|
|
|
|
}
|
|
|
|
|
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 21:07:37 -05:00
|
|
|
@Component({
|
|
|
|
selector: 'app-cmp',
|
|
|
|
template: `root { <router-outlet></router-outlet> }`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
2015-07-28 01:46:09 -04:00
|
|
|
@RouteConfig([
|
|
|
|
new Route({path: '/parent/...', component: ParentCmp}),
|
|
|
|
new Route({path: '/super-parent/...', component: SuperParentCmp})
|
|
|
|
])
|
2015-06-15 18:41:09 -04:00
|
|
|
class HierarchyAppCmp {
|
2015-06-22 15:14:19 -04:00
|
|
|
constructor(public router: Router, public location: LocationStrategy) {}
|
2015-05-29 17:58:41 -04:00
|
|
|
}
|
2015-06-08 21:04:13 -04: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 21:07:37 -05:00
|
|
|
@Component({selector: 'qs-cmp', template: `qParam = {{q}}`})
|
2015-07-21 04:26:43 -04:00
|
|
|
class QSCmp {
|
|
|
|
q: string;
|
|
|
|
constructor(params: RouteParams) { this.q = params.get('q'); }
|
|
|
|
}
|
|
|
|
|
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 21:07:37 -05:00
|
|
|
@Component({
|
|
|
|
selector: 'app-cmp',
|
|
|
|
template: `<router-outlet></router-outlet>`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
2015-07-21 04:26:43 -04:00
|
|
|
@RouteConfig([new Route({path: '/qs', component: QSCmp})])
|
|
|
|
class QueryStringAppCmp {
|
|
|
|
constructor(public router: Router, public location: LocationStrategy) {}
|
|
|
|
}
|
|
|
|
|
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 21:07:37 -05:00
|
|
|
@Component({selector: 'oops-cmp', template: "oh no"})
|
2015-06-08 21:04:13 -04:00
|
|
|
class BrokenCmp {
|
|
|
|
constructor() { throw new BaseException('oops!'); }
|
|
|
|
}
|
|
|
|
|
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 21:07:37 -05:00
|
|
|
@Component({
|
|
|
|
selector: 'app-cmp',
|
|
|
|
template: `outer { <router-outlet></router-outlet> }`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
2015-07-13 19:12:48 -04:00
|
|
|
@RouteConfig([new Route({path: '/cause-error', component: BrokenCmp})])
|
2015-06-08 21:04:13 -04:00
|
|
|
class BrokenAppCmp {
|
2015-06-22 15:14:19 -04:00
|
|
|
constructor(public router: Router, public location: LocationStrategy) {}
|
2015-06-08 21:04:13 -04:00
|
|
|
}
|