之前感觉Angular2这玩意越看越像jsp, 又是一大堆根本记不住的语法
现在看来是把后端MVC那一套也搞到前端来了… 估计又是一堆依赖注入的配置
1.设置 base 标签
推荐加一级后缀名, 比如.component.ts和 .service.ts12<head> <base href="/">
## 2.main.js里加载router12345678import { bootstrap } from '@angular/platform-browser-dynamic';import { AppComponent } from './app.component';import { appRouterProviders } from './app.routes';bootstrap(AppComponent, [ appRouterProviders]);
3.app.routes.ts
|
|
app.component.ts
Router的内容会被渲染到1234567891011121314151617@Component({ template: ` <nav> <a [routerLink]="['/dashboard']" routerLinkActive="active">Dashboard</a> <a [routerLink]="['/heroes']" routerLinkActive="active">Heroes</a> </nav> <router-outlet></router-outlet> `, directives: [ROUTER_DIRECTIVES],})...``` 返回就是url操作``` jsgoBack() { window.history.back();}
以path: ‘detail/:id’为例
|
|
|
|
管道
|
|