【发布时间】:2016-02-24 01:21:45
【问题描述】:
我有我的main.component.ts 代码:
它的位置是:root/
import {Component, OnInit, OnChanges, IterableDiffers} from 'angular2/core';
import {TypeService} from './type/type.service';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
import {Router} from 'angular2/router';
@Component({
selector: 'my-app',
providers: [],
directives: [ROUTER_DIRECTIVES],
template: `
<a [routerLink]="['Type']">Type</a>
<router-outlet></router-outlet>
`
})
@RouteConfig([
{path:'/type', name: 'Type', component: TypeService}
])
export class AppComponent{
constructor(private _router: Router){}
}
然后我有我的type.component.ts 代码:
它的位置是:root/type
import {Component, OnInit} from 'angular2/core';
import {DirectoryComponent} from '../main/main.component';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
import {Router} from 'angular2/router';
import {AppComponent} from '../app.component';
import {Http} from 'angular2/http';
@Component({
selector: 'type',
directives: [ROUTER_DIRECTIVES],
template: `<h1>hi</h1>`
})
export class TypeService{
constructor(
private _router: Router) {}
}
当我在主应用程序中单击类型链接时,它会将我带到 root/type 并加载类型组件。但是,如果我按重新加载它会给我一个 Not Found 错误。
我该如何做才能直接通过 url 访问组件?
【问题讨论】: