2015-08-24 14:24:53 -04:00
|
|
|
import {
|
2015-10-31 12:50:19 -04:00
|
|
|
ComponentFixture,
|
2015-08-24 14:24:53 -04:00
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
xdescribe,
|
|
|
|
describe,
|
|
|
|
dispatchEvent,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
beforeEachBindings,
|
|
|
|
it,
|
|
|
|
xit,
|
|
|
|
TestComponentBuilder,
|
|
|
|
proxy,
|
2015-09-04 01:01:36 -04:00
|
|
|
SpyObject
|
2015-10-13 03:29:13 -04:00
|
|
|
} from 'angular2/testing_internal';
|
2015-08-24 14:24:53 -04:00
|
|
|
|
2015-08-26 14:41:41 -04:00
|
|
|
import {NumberWrapper} from 'angular2/src/core/facade/lang';
|
2015-09-11 17:50:41 -04:00
|
|
|
import {PromiseWrapper} from 'angular2/src/core/facade/async';
|
2015-10-26 13:18:08 -04:00
|
|
|
import {ListWrapper} from 'angular2/src/core/facade/collection';
|
2015-08-24 14:24:53 -04:00
|
|
|
|
2015-10-11 01:11:13 -04:00
|
|
|
import {provide, Component, DirectiveResolver, View} from 'angular2/core';
|
2015-08-24 14:24:53 -04:00
|
|
|
|
|
|
|
import {SpyLocation} from 'angular2/src/mock/location_mock';
|
|
|
|
import {
|
|
|
|
Location,
|
|
|
|
Router,
|
|
|
|
RouteRegistry,
|
|
|
|
RouterLink,
|
|
|
|
RouterOutlet,
|
2015-09-11 17:50:41 -04:00
|
|
|
AsyncRoute,
|
2015-08-24 14:24:53 -04:00
|
|
|
Route,
|
|
|
|
RouteParams,
|
2015-08-31 00:27:11 -04:00
|
|
|
RouteConfig,
|
|
|
|
ROUTER_DIRECTIVES
|
2015-08-24 14:24:53 -04:00
|
|
|
} from 'angular2/router';
|
2015-09-21 22:58:45 -04:00
|
|
|
import {RootRouter} from 'angular2/src/router/router';
|
2015-08-24 14:24:53 -04:00
|
|
|
|
2015-08-20 17:28:25 -04:00
|
|
|
import {DOM} from 'angular2/src/core/dom/dom_adapter';
|
2015-08-24 14:24:53 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('router-link directive', function() {
|
|
|
|
var tcb: TestComponentBuilder;
|
2015-10-31 12:50:19 -04:00
|
|
|
var fixture: ComponentFixture;
|
2015-09-11 16:45:31 -04:00
|
|
|
var router, location;
|
2015-08-24 14:24:53 -04:00
|
|
|
|
|
|
|
beforeEachBindings(() => [
|
|
|
|
RouteRegistry,
|
|
|
|
DirectiveResolver,
|
2015-10-12 14:30:34 -04:00
|
|
|
provide(Location, {useClass: SpyLocation}),
|
2015-10-11 01:11:13 -04:00
|
|
|
provide(Router,
|
|
|
|
{
|
2015-10-12 14:30:34 -04:00
|
|
|
useFactory:
|
2015-10-11 01:11:13 -04:00
|
|
|
(registry, location) => { return new RootRouter(registry, location, MyComp); },
|
|
|
|
deps: [RouteRegistry, Location]
|
|
|
|
})
|
2015-08-24 14:24:53 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
beforeEach(inject([TestComponentBuilder, Router, Location], (tcBuilder, rtr, loc) => {
|
|
|
|
tcb = tcBuilder;
|
|
|
|
router = rtr;
|
|
|
|
location = loc;
|
|
|
|
}));
|
|
|
|
|
|
|
|
function compile(template: string = "<router-outlet></router-outlet>") {
|
|
|
|
return tcb.overrideView(MyComp, new View({
|
|
|
|
template: ('<div>' + template + '</div>'),
|
|
|
|
directives: [RouterOutlet, RouterLink]
|
|
|
|
}))
|
|
|
|
.createAsync(MyComp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((tc) => { fixture = tc; });
|
2015-08-24 14:24:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should generate absolute hrefs that include the base href',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
location.setBaseHref('/my/base');
|
2015-09-14 20:36:32 -04:00
|
|
|
compile('<a href="hello" [router-link]="[\'./User\']"></a>')
|
2015-10-25 05:30:27 -04:00
|
|
|
.then((_) => router.config(
|
|
|
|
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
|
2015-09-09 00:41:56 -04:00
|
|
|
.then((_) => router.navigateByUrl('/a/b'))
|
2015-08-24 14:24:53 -04:00
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
|
|
|
expect(getHref(fixture)).toEqual('/my/base/user');
|
2015-08-24 14:24:53 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should generate link hrefs without params', inject([AsyncTestCompleter], (async) => {
|
2015-09-14 20:36:32 -04:00
|
|
|
compile('<a href="hello" [router-link]="[\'./User\']"></a>')
|
2015-10-25 05:30:27 -04:00
|
|
|
.then((_) => router.config(
|
|
|
|
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
|
2015-09-09 00:41:56 -04:00
|
|
|
.then((_) => router.navigateByUrl('/a/b'))
|
2015-08-24 14:24:53 -04:00
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
|
|
|
expect(getHref(fixture)).toEqual('/user');
|
2015-08-24 14:24:53 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should generate link hrefs with params', inject([AsyncTestCompleter], (async) => {
|
2015-09-14 20:36:32 -04:00
|
|
|
compile('<a href="hello" [router-link]="[\'./User\', {name: name}]">{{name}}</a>')
|
2015-08-24 14:24:53 -04:00
|
|
|
.then((_) => router.config(
|
2015-10-25 05:30:27 -04:00
|
|
|
[new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
|
2015-09-09 00:41:56 -04:00
|
|
|
.then((_) => router.navigateByUrl('/a/b'))
|
2015-08-24 14:24:53 -04:00
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.name = 'brian';
|
|
|
|
fixture.detectChanges();
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('brian');
|
|
|
|
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[0].nativeElement,
|
2015-09-11 16:45:31 -04:00
|
|
|
'href'))
|
2015-08-24 14:24:53 -04:00
|
|
|
.toEqual('/user/brian');
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should generate link hrefs from a child to its sibling',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
compile()
|
2015-10-25 05:30:27 -04:00
|
|
|
.then(
|
|
|
|
(_) => router.config(
|
|
|
|
[new Route({path: '/page/:number', component: SiblingPageCmp, name: 'Page'})]))
|
2015-09-09 00:41:56 -04:00
|
|
|
.then((_) => router.navigateByUrl('/page/1'))
|
2015-08-24 14:24:53 -04:00
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
|
|
|
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
|
2015-09-11 16:45:31 -04:00
|
|
|
.componentViewChildren[0]
|
|
|
|
.nativeElement,
|
|
|
|
'href'))
|
2015-08-24 14:24:53 -04:00
|
|
|
.toEqual('/page/2');
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-10-26 13:18:08 -04:00
|
|
|
it('should generate link hrefs from a child to its sibling with no leading slash',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
compile()
|
|
|
|
.then((_) => router.config([
|
2015-10-25 05:30:27 -04:00
|
|
|
new Route(
|
|
|
|
{path: '/page/:number', component: NoPrefixSiblingPageCmp, name: 'Page'})
|
2015-10-26 13:18:08 -04:00
|
|
|
]))
|
|
|
|
.then((_) => router.navigateByUrl('/page/1'))
|
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
|
|
|
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
|
2015-10-26 13:18:08 -04:00
|
|
|
.componentViewChildren[0]
|
|
|
|
.nativeElement,
|
|
|
|
'href'))
|
|
|
|
.toEqual('/page/2');
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should generate link hrefs to a child with no leading slash',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
compile()
|
|
|
|
.then((_) => router.config([
|
2015-10-25 05:30:27 -04:00
|
|
|
new Route({path: '/book/:title/...', component: NoPrefixBookCmp, name: 'Book'})
|
2015-10-26 13:18:08 -04:00
|
|
|
]))
|
|
|
|
.then((_) => router.navigateByUrl('/book/1984/page/1'))
|
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
|
|
|
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
|
2015-10-26 13:18:08 -04:00
|
|
|
.componentViewChildren[0]
|
|
|
|
.nativeElement,
|
|
|
|
'href'))
|
|
|
|
.toEqual('/book/1984/page/100');
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should throw when links without a leading slash are ambiguous',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
compile()
|
|
|
|
.then((_) => router.config([
|
2015-10-25 05:30:27 -04:00
|
|
|
new Route({path: '/book/:title/...', component: AmbiguousBookCmp, name: 'Book'})
|
2015-10-26 13:18:08 -04:00
|
|
|
]))
|
|
|
|
.then((_) => router.navigateByUrl('/book/1984/page/1'))
|
|
|
|
.then((_) => {
|
|
|
|
var link = ListWrapper.toJSON(['Book', {number: 100}]);
|
2015-10-31 12:50:19 -04:00
|
|
|
expect(() => fixture.detectChanges())
|
2015-10-26 13:18:08 -04:00
|
|
|
.toThrowErrorWith(
|
|
|
|
`Link "${link}" is ambiguous, use "./" or "../" to disambiguate.`);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-09-11 17:50:41 -04:00
|
|
|
it('should generate link hrefs when asynchronously loaded',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
compile()
|
|
|
|
.then((_) => router.config([
|
|
|
|
new AsyncRoute({
|
|
|
|
path: '/child-with-grandchild/...',
|
|
|
|
loader: parentCmpLoader,
|
2015-10-25 05:30:27 -04:00
|
|
|
name: 'ChildWithGrandchild'
|
2015-09-11 17:50:41 -04:00
|
|
|
})
|
|
|
|
]))
|
2015-09-14 20:36:32 -04:00
|
|
|
.then((_) => router.navigate(['/ChildWithGrandchild']))
|
2015-09-11 17:50:41 -04:00
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
|
|
|
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
|
2015-09-11 16:45:31 -04:00
|
|
|
.componentViewChildren[0]
|
|
|
|
.nativeElement,
|
|
|
|
'href'))
|
2015-09-11 17:50:41 -04:00
|
|
|
.toEqual('/child-with-grandchild/grandchild');
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-08-24 14:24:53 -04:00
|
|
|
it('should generate relative links preserving the existing parent route',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
compile()
|
|
|
|
.then((_) => router.config(
|
2015-10-25 05:30:27 -04:00
|
|
|
[new Route({path: '/book/:title/...', component: BookCmp, name: 'Book'})]))
|
2015-09-09 00:41:56 -04:00
|
|
|
.then((_) => router.navigateByUrl('/book/1984/page/1'))
|
2015-08-24 14:24:53 -04:00
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
|
|
|
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
|
2015-09-11 16:45:31 -04:00
|
|
|
.componentViewChildren[0]
|
|
|
|
.nativeElement,
|
|
|
|
'href'))
|
2015-08-24 14:24:53 -04:00
|
|
|
.toEqual('/book/1984/page/100');
|
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
|
2015-08-24 14:24:53 -04:00
|
|
|
.componentViewChildren[2]
|
|
|
|
.componentViewChildren[0]
|
|
|
|
.nativeElement,
|
|
|
|
'href'))
|
|
|
|
.toEqual('/book/1984/page/2');
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-08-31 00:27:11 -04:00
|
|
|
describe('router-link-active CSS class', () => {
|
|
|
|
it('should be added to the associated element', inject([AsyncTestCompleter], (async) => {
|
|
|
|
router.config([
|
2015-10-25 05:30:27 -04:00
|
|
|
new Route({path: '/child', component: HelloCmp, name: 'Child'}),
|
|
|
|
new Route({path: '/better-child', component: Hello2Cmp, name: 'BetterChild'})
|
2015-08-31 00:27:11 -04:00
|
|
|
])
|
2015-09-14 20:36:32 -04:00
|
|
|
.then((_) => compile(`<a [router-link]="['./Child']" class="child-link">Child</a>
|
|
|
|
<a [router-link]="['./BetterChild']" class="better-child-link">Better Child</a>
|
2015-08-31 00:27:11 -04:00
|
|
|
<router-outlet></router-outlet>`))
|
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
var element = fixture.debugElement.nativeElement;
|
2015-08-31 00:27:11 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
2015-08-31 00:27:11 -04:00
|
|
|
|
|
|
|
var link1 = DOM.querySelector(element, '.child-link');
|
|
|
|
var link2 = DOM.querySelector(element, '.better-child-link');
|
|
|
|
|
|
|
|
expect(link1).not.toHaveCssClass('router-link-active');
|
|
|
|
expect(link2).not.toHaveCssClass('router-link-active');
|
|
|
|
|
|
|
|
router.subscribe((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
2015-08-31 00:27:11 -04:00
|
|
|
|
|
|
|
expect(link1).not.toHaveCssClass('router-link-active');
|
|
|
|
expect(link2).toHaveCssClass('router-link-active');
|
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
2015-09-09 00:41:56 -04:00
|
|
|
router.navigateByUrl('/better-child');
|
2015-08-31 00:27:11 -04:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should be added to links in child routes', inject([AsyncTestCompleter], (async) => {
|
|
|
|
router.config([
|
2015-10-25 05:30:27 -04:00
|
|
|
new Route({path: '/child', component: HelloCmp, name: 'Child'}),
|
2015-08-31 00:27:11 -04:00
|
|
|
new Route({
|
|
|
|
path: '/child-with-grandchild/...',
|
|
|
|
component: ParentCmp,
|
2015-10-25 05:30:27 -04:00
|
|
|
name: 'ChildWithGrandchild'
|
2015-08-31 00:27:11 -04:00
|
|
|
})
|
|
|
|
])
|
2015-09-14 20:36:32 -04:00
|
|
|
.then((_) => compile(`<a [router-link]="['./Child']" class="child-link">Child</a>
|
|
|
|
<a [router-link]="['./ChildWithGrandchild/Grandchild']" class="child-with-grandchild-link">Better Child</a>
|
2015-08-31 00:27:11 -04:00
|
|
|
<router-outlet></router-outlet>`))
|
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
var element = fixture.debugElement.nativeElement;
|
2015-08-31 00:27:11 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
2015-08-31 00:27:11 -04:00
|
|
|
|
|
|
|
var link1 = DOM.querySelector(element, '.child-link');
|
|
|
|
var link2 = DOM.querySelector(element, '.child-with-grandchild-link');
|
|
|
|
|
|
|
|
expect(link1).not.toHaveCssClass('router-link-active');
|
|
|
|
expect(link2).not.toHaveCssClass('router-link-active');
|
|
|
|
|
|
|
|
router.subscribe((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
2015-08-31 00:27:11 -04:00
|
|
|
|
|
|
|
expect(link1).not.toHaveCssClass('router-link-active');
|
|
|
|
expect(link2).toHaveCssClass('router-link-active');
|
|
|
|
|
|
|
|
var link3 = DOM.querySelector(element, '.grandchild-link');
|
|
|
|
var link4 = DOM.querySelector(element, '.better-grandchild-link');
|
|
|
|
|
|
|
|
expect(link3).toHaveCssClass('router-link-active');
|
|
|
|
expect(link4).not.toHaveCssClass('router-link-active');
|
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
2015-09-09 00:41:56 -04:00
|
|
|
router.navigateByUrl('/child-with-grandchild/grandchild');
|
2015-08-31 00:27:11 -04:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2015-08-24 14:24:53 -04:00
|
|
|
describe('when clicked', () => {
|
|
|
|
|
|
|
|
var clickOnElement = function(view) {
|
2015-10-31 12:50:19 -04:00
|
|
|
var anchorEl = fixture.debugElement.componentViewChildren[0].nativeElement;
|
2015-08-24 14:24:53 -04:00
|
|
|
var dispatchedEvent = DOM.createMouseEvent('click');
|
|
|
|
DOM.dispatchEvent(anchorEl, dispatchedEvent);
|
|
|
|
return dispatchedEvent;
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should navigate to link hrefs without params', inject([AsyncTestCompleter], (async) => {
|
2015-09-14 20:36:32 -04:00
|
|
|
compile('<a href="hello" [router-link]="[\'./User\']"></a>')
|
2015-08-24 14:24:53 -04:00
|
|
|
.then((_) => router.config(
|
2015-10-25 05:30:27 -04:00
|
|
|
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
|
2015-09-09 00:41:56 -04:00
|
|
|
.then((_) => router.navigateByUrl('/a/b'))
|
2015-08-24 14:24:53 -04:00
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
2015-08-24 14:24:53 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
var dispatchedEvent = clickOnElement(fixture);
|
2015-08-24 14:24:53 -04:00
|
|
|
expect(DOM.isPrevented(dispatchedEvent)).toBe(true);
|
|
|
|
|
|
|
|
// router navigation is async.
|
|
|
|
router.subscribe((_) => {
|
|
|
|
expect(location.urlChanges).toEqual(['/user']);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
});
|
2015-09-09 10:41:11 -04:00
|
|
|
}));
|
2015-08-24 14:24:53 -04:00
|
|
|
|
|
|
|
it('should navigate to link hrefs in presence of base href',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
location.setBaseHref('/base');
|
2015-09-14 20:36:32 -04:00
|
|
|
compile('<a href="hello" [router-link]="[\'./User\']"></a>')
|
2015-08-24 14:24:53 -04:00
|
|
|
.then((_) => router.config(
|
2015-10-25 05:30:27 -04:00
|
|
|
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
|
2015-09-09 00:41:56 -04:00
|
|
|
.then((_) => router.navigateByUrl('/a/b'))
|
2015-08-24 14:24:53 -04:00
|
|
|
.then((_) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
2015-08-24 14:24:53 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
var dispatchedEvent = clickOnElement(fixture);
|
2015-08-24 14:24:53 -04:00
|
|
|
expect(DOM.isPrevented(dispatchedEvent)).toBe(true);
|
|
|
|
|
|
|
|
// router navigation is async.
|
|
|
|
router.subscribe((_) => {
|
|
|
|
expect(location.urlChanges).toEqual(['/base/user']);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
});
|
2015-09-09 10:41:11 -04:00
|
|
|
}));
|
2015-08-24 14:24:53 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
function getHref(tc: ComponentFixture) {
|
2015-09-11 16:45:31 -04:00
|
|
|
return DOM.getAttribute(tc.debugElement.componentViewChildren[0].nativeElement, 'href');
|
2015-08-24 14:24:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'my-comp'})
|
|
|
|
class MyComp {
|
|
|
|
name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'user-cmp'})
|
|
|
|
@View({template: "hello {{user}}"})
|
|
|
|
class UserCmp {
|
|
|
|
user: string;
|
|
|
|
constructor(params: RouteParams) { this.user = params.get('name'); }
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'page-cmp'})
|
|
|
|
@View({
|
|
|
|
template:
|
2015-09-14 20:36:32 -04:00
|
|
|
`page #{{pageNumber}} | <a href="hello" [router-link]="[\'../Page\', {number: nextPage}]">next</a>`,
|
2015-08-24 14:24:53 -04:00
|
|
|
directives: [RouterLink]
|
|
|
|
})
|
|
|
|
class SiblingPageCmp {
|
|
|
|
pageNumber: number;
|
|
|
|
nextPage: number;
|
|
|
|
constructor(params: RouteParams) {
|
|
|
|
this.pageNumber = NumberWrapper.parseInt(params.get('number'), 10);
|
|
|
|
this.nextPage = this.pageNumber + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 13:18:08 -04:00
|
|
|
@Component({selector: 'page-cmp'})
|
|
|
|
@View({
|
|
|
|
template:
|
|
|
|
`page #{{pageNumber}} | <a href="hello" [router-link]="[\'Page\', {number: nextPage}]">next</a>`,
|
|
|
|
directives: [RouterLink]
|
|
|
|
})
|
|
|
|
class NoPrefixSiblingPageCmp {
|
|
|
|
pageNumber: number;
|
|
|
|
nextPage: number;
|
|
|
|
constructor(params: RouteParams) {
|
|
|
|
this.pageNumber = NumberWrapper.parseInt(params.get('number'), 10);
|
|
|
|
this.nextPage = this.pageNumber + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-31 00:27:11 -04:00
|
|
|
@Component({selector: 'hello-cmp'})
|
|
|
|
@View({template: 'hello'})
|
|
|
|
class HelloCmp {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'hello2-cmp'})
|
|
|
|
@View({template: 'hello2'})
|
|
|
|
class Hello2Cmp {
|
|
|
|
}
|
|
|
|
|
2015-09-11 17:50:41 -04:00
|
|
|
function parentCmpLoader() {
|
|
|
|
return PromiseWrapper.resolve(ParentCmp);
|
|
|
|
}
|
|
|
|
|
2015-08-31 00:27:11 -04:00
|
|
|
@Component({selector: 'parent-cmp'})
|
|
|
|
@View({
|
2015-09-14 20:36:32 -04:00
|
|
|
template: `{ <a [router-link]="['./Grandchild']" class="grandchild-link">Grandchild</a>
|
|
|
|
<a [router-link]="['./BetterGrandchild']" class="better-grandchild-link">Better Grandchild</a>
|
2015-08-31 00:27:11 -04:00
|
|
|
<router-outlet></router-outlet> }`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
|
|
|
@RouteConfig([
|
2015-10-25 05:30:27 -04:00
|
|
|
new Route({path: '/grandchild', component: HelloCmp, name: 'Grandchild'}),
|
|
|
|
new Route({path: '/better-grandchild', component: Hello2Cmp, name: 'BetterGrandchild'})
|
2015-08-31 00:27:11 -04:00
|
|
|
])
|
|
|
|
class ParentCmp {
|
|
|
|
constructor(public router: Router) {}
|
|
|
|
}
|
|
|
|
|
2015-08-24 14:24:53 -04:00
|
|
|
@Component({selector: 'book-cmp'})
|
|
|
|
@View({
|
2015-09-14 20:36:32 -04:00
|
|
|
template: `<a href="hello" [router-link]="[\'./Page\', {number: 100}]">{{title}}</a> |
|
2015-08-24 14:24:53 -04:00
|
|
|
<router-outlet></router-outlet>`,
|
2015-08-31 00:27:11 -04:00
|
|
|
directives: ROUTER_DIRECTIVES
|
2015-08-24 14:24:53 -04:00
|
|
|
})
|
2015-10-25 05:30:27 -04:00
|
|
|
@RouteConfig([new Route({path: '/page/:number', component: SiblingPageCmp, name: 'Page'})])
|
2015-08-24 14:24:53 -04:00
|
|
|
class BookCmp {
|
|
|
|
title: string;
|
|
|
|
constructor(params: RouteParams) { this.title = params.get('title'); }
|
|
|
|
}
|
2015-10-26 13:18:08 -04:00
|
|
|
|
|
|
|
@Component({selector: 'book-cmp'})
|
|
|
|
@View({
|
|
|
|
template: `<a href="hello" [router-link]="[\'Page\', {number: 100}]">{{title}}</a> |
|
|
|
|
<router-outlet></router-outlet>`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
2015-10-25 05:30:27 -04:00
|
|
|
@RouteConfig([new Route({path: '/page/:number', component: SiblingPageCmp, name: 'Page'})])
|
2015-10-26 13:18:08 -04:00
|
|
|
class NoPrefixBookCmp {
|
|
|
|
title: string;
|
|
|
|
constructor(params: RouteParams) { this.title = params.get('title'); }
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'book-cmp'})
|
|
|
|
@View({
|
|
|
|
template: `<a href="hello" [router-link]="[\'Book\', {number: 100}]">{{title}}</a> |
|
|
|
|
<router-outlet></router-outlet>`,
|
|
|
|
directives: ROUTER_DIRECTIVES
|
|
|
|
})
|
2015-10-25 05:30:27 -04:00
|
|
|
@RouteConfig([new Route({path: '/page/:number', component: SiblingPageCmp, name: 'Book'})])
|
2015-10-26 13:18:08 -04:00
|
|
|
class AmbiguousBookCmp {
|
|
|
|
title: string;
|
|
|
|
constructor(params: RouteParams) { this.title = params.get('title'); }
|
|
|
|
}
|