@title
路由
@intro
添加 Angular 组件路由,并且学习在视图之间导航
@description
There are new requirements for the Tour of Heroes app:
我们收到了《英雄指南》的一些新需求:
* Add a *Dashboard* view.
添加一个*仪表盘*视图。
* Add the ability to navigate between the *Heroes* and *Dashboard* views.
在*英雄列表*和*仪表盘*视图之间导航。
* When users click a hero name in either view, navigate to a detail view of the selected hero.
无论在哪个视图中点击一个英雄,都会导航到该英雄的详情页。
* When users click a *deep link* in an email, open the detail view for a particular hero.
在邮件中点击一个*深链接*,会直接打开一个特定英雄的详情视图。
When you’re done, users will be able to navigate the app like this:
完成时,用户就能像这样在应用中导航:
app.component.ts
file to heroes.component.ts
.
把app.component.ts
文件改名为heroes.component.ts
。
* Rename the `AppComponent` class as `HeroesComponent` (rename locally, _only_ in this file).
把`AppComponent`类改名为`HeroesComponent`(注意,*只*在这一个文件中改名)。
* Rename the selector `my-app` as `my-heroes`.
把`my-app`选择器改名为`my-heroes`。
src/app/app.component.ts
.
创建一个名叫src/app/app.component.ts的新文件。
* Define an exported `AppComponent` class.
定义一个导出的 `AppComponent`类。
* Add an `@Component` decorator above the class with a `my-app` selector.
在类的上方添加`@Component`元数据装饰器,装饰器带有`my-app`选择器。
* Move the following from `HeroesComponent` to `AppComponent`:
将下面的项目从`HeroesComponent`移到`AppComponent`:
* `title` class property.
`title`类属性
* `@Component` template `providers
中移除HeroService
dashboard.component.ts
, add the following `import` statements.
打开dashboard.component.ts
文件,并添加下列`import`语句。
hero-detail.component.html
:
修改模板,添加这个按钮以提醒我们还要做更多的改进,
并把模板移到独立的hero-detail.component.html文件中去。