diff --git a/public/docs/_examples/package.json b/public/docs/_examples/package.json index 1cb56e65de..50622f9aaf 100644 --- a/public/docs/_examples/package.json +++ b/public/docs/_examples/package.json @@ -31,7 +31,7 @@ "@angular/http": "2.0.0-rc.2", "@angular/platform-browser": "2.0.0-rc.2", "@angular/platform-browser-dynamic": "2.0.0-rc.2", - "@angular/router": "2.0.0-rc.2", + "@angular/router": "3.0.0-alpha.7", "@angular/router-deprecated": "2.0.0-rc.2", "@angular/upgrade": "2.0.0-rc.2", "angular2-in-memory-web-api": "0.0.12", diff --git a/public/docs/_examples/router/e2e-spec.ts b/public/docs/_examples/router/e2e-spec.ts index f86293e823..ac3e36f4ea 100644 --- a/public/docs/_examples/router/e2e-spec.ts +++ b/public/docs/_examples/router/e2e-spec.ts @@ -24,14 +24,18 @@ describe('Router', function () { heroDetail: element(by.css('my-app > undefined > div')), heroDetailTitle: element(by.css('my-app > undefined > div > h3')), + adminHref: hrefEles.get(2), + loginHref: hrefEles.get(3) }; } it('should be able to see the start screen', function () { let page = getPageStruct(); - expect(page.hrefs.count()).toEqual(2, 'should be two dashboard choices'); + expect(page.hrefs.count()).toEqual(4, 'should be two dashboard choices'); expect(page.crisisHref.getText()).toEqual('Crisis Center'); expect(page.heroesHref.getText()).toEqual('Heroes'); + expect(page.adminHref.getText()).toEqual('Crisis Admin'); + expect(page.loginHref.getText()).toEqual('Login'); }); it('should be able to see crises center items', function () { diff --git a/public/docs/_examples/router/ts/app/app.component.2.ts b/public/docs/_examples/router/ts/app/app.component.2.ts index 779d43a063..f1580cf6f8 100644 --- a/public/docs/_examples/router/ts/app/app.component.2.ts +++ b/public/docs/_examples/router/ts/app/app.component.2.ts @@ -3,7 +3,7 @@ // #docregion import { Component } from '@angular/core'; -import { Router, ROUTER_DIRECTIVES } from '@angular/router'; +import { ROUTER_DIRECTIVES } from '@angular/router'; // #enddocregion /* diff --git a/public/docs/_examples/router/ts/app/app.routes.1.ts b/public/docs/_examples/router/ts/app/app.routes.1.ts index 480b4eb95c..8c4caeda55 100644 --- a/public/docs/_examples/router/ts/app/app.routes.1.ts +++ b/public/docs/_examples/router/ts/app/app.routes.1.ts @@ -16,11 +16,11 @@ import { HeroDetailComponent } from './heroes/hero-detail.component'; // #docregion route-config export const routes: RouterConfig = [ // #docregion route-defs - { path: '/crisis-center', component: CrisisCenterComponent }, - { path: '/heroes', component: HeroListComponent }, + { path: 'crisis-center', component: CrisisCenterComponent }, + { path: 'heroes', component: HeroListComponent }, // #enddocregion route-defs // #docregion hero-detail-route - { path: '/hero/:id', component: HeroDetailComponent } + { path: 'hero/:id', component: HeroDetailComponent } // #enddocregion hero-detail-route ]; diff --git a/public/docs/_examples/router/ts/app/app.routes.2.ts b/public/docs/_examples/router/ts/app/app.routes.2.ts index 57c069c81d..d0d64e2ea0 100644 --- a/public/docs/_examples/router/ts/app/app.routes.2.ts +++ b/public/docs/_examples/router/ts/app/app.routes.2.ts @@ -9,8 +9,8 @@ import { HeroListComponent } from './hero-list.component'; // #docregion route-config export const routes: RouterConfig = [ - { path: '/crisis-center', component: CrisisListComponent }, - { path: '/heroes', component: HeroListComponent } + { path: 'crisis-center', component: CrisisListComponent }, + { path: 'heroes', component: HeroListComponent } ]; export const APP_ROUTER_PROVIDERS = [ diff --git a/public/docs/_examples/router/ts/app/app.routes.3.ts b/public/docs/_examples/router/ts/app/app.routes.3.ts index f7becf70ea..c6e9cffc72 100644 --- a/public/docs/_examples/router/ts/app/app.routes.3.ts +++ b/public/docs/_examples/router/ts/app/app.routes.3.ts @@ -7,7 +7,7 @@ import { HeroesRoutes } from './heroes/heroes.routes'; export const routes = [ ...HeroesRoutes, - { path: '/crisis-center', component: CrisisListComponent } + { path: 'crisis-center', component: CrisisListComponent } ]; export const APP_ROUTER_PROVIDERS = [ diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.1.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.1.ts index 0bd846c600..0c50d6b7df 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.1.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.1.ts @@ -7,11 +7,11 @@ import { CrisisCenterComponent } from './crisis-center.component'; // #docregion routes export const CrisisCenterRoutes: RouterConfig = [ { - path: '/crisis-center', + path: 'crisis-center', component: CrisisCenterComponent, children: [ - { path: '/', component: CrisisListComponent }, - { path: '/:id', component: CrisisDetailComponent } + { path: ':id', component: CrisisDetailComponent }, + { path: '', component: CrisisListComponent } ] } ]; diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.2.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.2.ts index 2856544136..43eadbd55e 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.2.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.2.ts @@ -6,17 +6,20 @@ import { CrisisCenterComponent } from './crisis-center.component'; // #docregion routes export const CrisisCenterRoutes: RouterConfig = [ + // #docregion redirect { - path: '/crisis-center', + path: '', + redirectTo: '/crisis-center', + terminal: true + }, + // #enddocregion redirect + { + path: 'crisis-center', component: CrisisCenterComponent, - index: true, children: [ - { path: '/:id', component: CrisisDetailComponent }, - { path: '/', component: CrisisListComponent, - index: true - } + { path: ':id', component: CrisisDetailComponent }, + { path: '', component: CrisisListComponent } ] } ]; // #enddocregion routes - diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.3.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.3.ts index 5d7170d500..1f194ac6f7 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.3.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.3.ts @@ -10,25 +10,28 @@ import { CanDeactivateGuard } from '../interfaces'; export const CrisisCenterRoutes: RouterConfig = [ { - path: '/crisis-center', + path: '', + redirectTo: '/crisis-center', + terminal: true + }, + { + path: 'crisis-center', component: CrisisCenterComponent, - index: true, children: [ // #docregion admin-route-no-guard { - path: '/admin', + path: 'admin', component: CrisisAdminComponent }, // #enddocregion admin-route-no-guard { - path: '/:id', + path: ':id', component: CrisisDetailComponent, canDeactivate: [CanDeactivateGuard] }, { - path: '/', - component: CrisisListComponent, - index: true + path: '', + component: CrisisListComponent } ] } @@ -40,7 +43,7 @@ export const CrisisCenterRoutes: RouterConfig = [ import { AuthGuard } from '../auth.guard'; { - path: '/admin', + path: 'admin', component: CrisisAdminComponent, canActivate: [AuthGuard] } diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.4.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.4.ts index 0e16b01d1c..f238e132a7 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.4.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.4.ts @@ -11,25 +11,28 @@ import { AuthGuard } from '../auth.guard'; export const CrisisCenterRoutes: RouterConfig = [ { - path: '/crisis-center', + path: '', + redirectTo: '/crisis-center', + terminal: true + }, + { + path: 'crisis-center', component: CrisisCenterComponent, - index: true, children: [ { - path: '/admin', + path: 'admin', component: CrisisAdminComponent, canActivate: [AuthGuard] }, { - path: '/:id', + path: ':id', component: CrisisDetailComponent, canDeactivate: [CanDeactivateGuard] }, // #docregion default-route { - path: '/', - component: CrisisListComponent, - index: true + path: '', + component: CrisisListComponent } // #enddocregion default-route ] @@ -42,7 +45,7 @@ export const CrisisCenterRoutes: RouterConfig = [ import { AuthGuard } from '../auth.guard'; { - path: '/admin', + path: 'admin', component: CrisisAdminComponent, canActivate: [AuthGuard] } diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.ts index f9d0a26f8d..a924aa5771 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis-center.routes.ts @@ -10,25 +10,29 @@ import { AuthGuard } from '../auth.guard'; export const CrisisCenterRoutes: RouterConfig = [ { - path: '/crisis-center', + path: '', + redirectTo: '/crisis-center', + terminal: true + }, + { + path: 'crisis-center', component: CrisisCenterComponent, - index: true, children: [ // #docregion admin-route { - path: '/admin', + path: 'admin', component: CrisisAdminComponent, canActivate: [AuthGuard] }, // #enddocregion admin-route { - path: '/:id', + path: ':id', component: CrisisDetailComponent, canDeactivate: [CanDeactivateGuard] }, - { path: '/', - component: CrisisListComponent, - index: true + { + path: '', + component: CrisisListComponent } ] } diff --git a/public/docs/_examples/router/ts/app/crisis-center/crisis.service.ts b/public/docs/_examples/router/ts/app/crisis-center/crisis.service.ts index 72e2500669..20597752cc 100644 --- a/public/docs/_examples/router/ts/app/crisis-center/crisis.service.ts +++ b/public/docs/_examples/router/ts/app/crisis-center/crisis.service.ts @@ -14,7 +14,7 @@ const CRISES = [ let crisesPromise = Promise.resolve(CRISES); // #docregion -import {Injectable} from '@angular/core'; +import { Injectable } from '@angular/core'; @Injectable() export class CrisisService { diff --git a/public/docs/_examples/router/ts/app/heroes/hero-detail.component.ts b/public/docs/_examples/router/ts/app/heroes/hero-detail.component.ts index 9f765d0ad0..bfa9ca6d0f 100644 --- a/public/docs/_examples/router/ts/app/heroes/hero-detail.component.ts +++ b/public/docs/_examples/router/ts/app/heroes/hero-detail.component.ts @@ -56,7 +56,7 @@ export class HeroDetailComponent implements OnInit, OnDestroy { let heroId = this.hero ? this.hero.id : null; // Pass along the hero id if available // so that the HeroList component can select that hero. - this.router.navigate(['/heroes'], { queryParams: { id: `${heroId}`, foo: 'foo' } }); + this.router.navigate(['/heroes'], { queryParams: { id: heroId, foo: 'foo' } }); } // #enddocregion gotoHeroes-navigate } diff --git a/public/docs/_examples/router/ts/app/heroes/heroes.routes.ts b/public/docs/_examples/router/ts/app/heroes/heroes.routes.ts index c4463cc8a1..80018d1f26 100644 --- a/public/docs/_examples/router/ts/app/heroes/heroes.routes.ts +++ b/public/docs/_examples/router/ts/app/heroes/heroes.routes.ts @@ -4,9 +4,9 @@ import { HeroListComponent } from './hero-list.component'; import { HeroDetailComponent } from './hero-detail.component'; export const HeroesRoutes: RouterConfig = [ - { path: '/heroes', component: HeroListComponent }, + { path: 'heroes', component: HeroListComponent }, // #docregion hero-detail-route - { path: '/hero/:id', component: HeroDetailComponent } + { path: 'hero/:id', component: HeroDetailComponent } // #enddocregion hero-detail-route ]; // #enddocregion diff --git a/public/docs/_examples/router/ts/app/login.component.ts b/public/docs/_examples/router/ts/app/login.component.ts index 898ca2d4c5..2790bfc79d 100755 --- a/public/docs/_examples/router/ts/app/login.component.ts +++ b/public/docs/_examples/router/ts/app/login.component.ts @@ -4,7 +4,6 @@ import { Router } from '@angular/router'; import { AuthService } from './auth.service'; @Component({ - selector: 'login', template: `
{{message}}
@@ -25,7 +24,7 @@ export class LoginComponent { } login() { - this.message = "Trying to log in ..."; + this.message = 'Trying to log in ...'; this.authService.login().subscribe(() => { this.setMessage(); diff --git a/public/docs/_examples/router/ts/app/login.routes.ts b/public/docs/_examples/router/ts/app/login.routes.ts index 71ad3cf9e4..6dabba376f 100644 --- a/public/docs/_examples/router/ts/app/login.routes.ts +++ b/public/docs/_examples/router/ts/app/login.routes.ts @@ -4,7 +4,7 @@ import { AuthService } from './auth.service'; import { LoginComponent } from './login.component'; export const LoginRoutes = [ - { path: '/login', component: LoginComponent } + { path: 'login', component: LoginComponent } ]; export const AUTH_PROVIDERS = [AuthGuard, AuthService]; diff --git a/public/docs/_examples/systemjs.config.plunker.js b/public/docs/_examples/systemjs.config.plunker.js index 0479c88703..bf2fc3de68 100644 --- a/public/docs/_examples/systemjs.config.plunker.js +++ b/public/docs/_examples/systemjs.config.plunker.js @@ -6,7 +6,7 @@ (function(global) { var ngVer = '@2.0.0-rc.2'; // lock in the angular package version; do not let it float to current! - var routerVer = '@3.0.0-alpha.3'; // lock router version + var routerVer = '@3.0.0-alpha.7'; // lock router version //map tells the System loader where to look for things var map = { diff --git a/public/docs/ts/latest/guide/router.jade b/public/docs/ts/latest/guide/router.jade index 853f735d65..a92d0386c0 100644 --- a/public/docs/ts/latest/guide/router.jade +++ b/public/docs/ts/latest/guide/router.jade @@ -47,7 +47,7 @@ include ../_util-fns * navigating under [program control](#navigate) * embedding critical information in the URL with [route parameters](#route-parameters) * add [child routes](#child-routing-component) under a feature section - * setting an [index route](#index) as the default + * [redirecting](#redirect) from one route to another * confirming or canceling navigation with [guards](#guards) * [CanActivate](#can-activate-guard) to prevent navigation to a route * [CanDeactivate](#can-deactivate-deactivate) to prevent navigation away from the current route @@ -100,6 +100,9 @@ include ../_util-fns The `RouterConfig` is an array of *routes* that describe how to navigate. Each *Route* maps a URL `path` to a component. + There are no **leading slashes** in our **path**. The router parses and builds the URL for us, + allowing us to use relative and absolute paths when navigating between application views. + The `:id` in the third route is a token for a route parameter. In a URL such as `/hero/42`, "42" is the value of the `id` parameter. The corresponding `HeroDetailComponent` will use that value to find and present the hero whose `id` is 42. @@ -167,7 +170,7 @@ table tr tdRoute
td.
- Defines how the router should navigate to a component based on a URL pattern.
+ Defines how the router should navigate to a component based on a URL pattern.
Most routes consist of a path and a component type.
tr
td RouterOutlet
@@ -343,10 +346,10 @@ figure.image-display
h4#import Import from the Component Router library
:marked
- We begin by importing some symbols from the router library.
-
+ We begin by importing some symbols from the router library.
+
The Component Router is in its own `@angular/router` package.
- It's not part of the Angular 2 core.
+ It's not part of the Angular 2 core.
The router is an optional service because not all applications need routing and,
depending on your requirements, you may need a different routing library.
@@ -371,17 +374,17 @@ h4#define-routes Define routes
* *When the application requests navigation to the path `/crisis-center`, create or retrieve an instance of
the `CrisisListComponent`, display its view, and update the browser's address location and history with the URL
- for that path.*
+ for that path.*
h4#provideRouter Call provideRouter
:marked
- We pass the route configuration to the `provideRouter` function which returns an array containing the configured
+ We pass the route configuration to the `provideRouter` function which returns an array containing the configured
`Router` service provider ... and some other, unseen providers that the routing library requires.
:marked
We add the `provideRouter` array to an `APP_ROUTER_PROVIDERS` array and export it.
- We could add *additional* service providers to `APP_ROUTER_PROVIDERS` —
+ We could add *additional* service providers to `APP_ROUTER_PROVIDERS` —
providers that are specific to our routing configuration.
We don't have any yet. We will have some later in this chapter.
@@ -398,10 +401,10 @@ h4#register-providers Register routing in bootstrap
and pass it as the second parameter of the `bootstrap` function.
+makeExample('router/ts/app/main.1.ts','all', 'main.ts')(format=".")
:marked
- Providing the router providers at the root makes the Router available everywhere in our application.
+ Providing the router providers at bootstrap makes the Router available everywhere in our application.
.alert.is-important
:marked
- We must register router providers in `bootstrap`.
+ We must register router providers in `bootstrap`.
We cannot wait to do it in `AppComponent`.
h3#shell The AppComponent shell
@@ -424,7 +427,7 @@ h3#router-outlet RouterOutlet
.l-sub-section
:marked
A template may hold exactly one ***unnamed*** `