【发布时间】:2016-03-19 06:13:12
【问题描述】:
我有一个简单的应用程序我在尝试导航到路线时遇到问题。 我的主要组件:
@Component({
selector: 'my-app',
template: `
<ul class="my-app">
<li>
<a [routerLink]="['Login']">Login</a>
</li>
<li>
<a [routerLink]="['Projects']">Projects</a>
</li>
</ul>
<br>
<router-outlet></router-outlet>`,
directives: [ROUTER_DIRECTIVES],
providers: [ROUTER_PROVIDERS]
})
@RouteConfig([
{
path: '/Login',
name: 'Login',
component: LoginFormComponent,
useAsDefault: false
},
{
path: '/Projects',
name: 'Projects',
component: ListProjectsComponent,
useAsDefault: true
}
])
export class AppComponent { ...
...
我有一个基本组件
@Component({
selector: 'login-form',
template:
`
<button (click)="goToProjects()">Go To Projects!</button>
`,
directives: [ROUTER_DIRECTIVES],
providers: [LoginService, ROUTER_PROVIDERS]
})
export class LoginFormComponent implements OnInit {
...
goToProjects(){
let link = ['Projects',{}];
this.router.navigate(link);
}
..
}
我将基本 Href 添加到主页“index.html”
<head>
<base href="/">
</head>
当我点击按钮时,地址栏中的 url 改变了,但视图没有显示,可能是什么问题?
【问题讨论】: