我有一个非常简单的应用程序Angular2路由 - 手动网址导航
我app.component.html看起来是这样的:
<a [routerLink]="['/Test']">CLICK ME</a>
<div class="main-container">
<router-outlet></router-outlet>
</div>
我app.component.ts看起来是这样的:
@Component({
selector: 'app',
templateUrl: 'app/app.component.html',
directives: [HomeComponent, TestComponent, ROUTER_DIRECTIVES]
})
@RouteConfig([
{path: '/', component: HomeComponent, as: 'HomeComponent'},
{path: '/test', component: TestComponent, as: 'Test'}
])
export class AppComponent { }
导航到我的应用程序,我去
http://localhost/app
这是完美的,它导航我到我的家庭组件视图如预期。 当我点击“按我”按钮,我浏览到
http://localhost/app/test
和预期的一样我的测试组件呈现......但是,如果我手动导航到
http://localhost/app/test
我家成分被加载而不是我的测试组件...什么给了?我如何设置路由,以便手动导航到测试网址实际上在路由器插座中返回测试组件的视图?这可能吗?我不想去,每次登陆页面...
您是否在index.html中设置了您的基础href?它应该像[文档建议](https://angular.io/docs/ts/latest/guide/router.html#!#base-href)' ' –
什么是你的angular2版本? –
beta17,基础href是好的,我有一个重新编写规则自动服务/app/index.html,我认为是需要获得PathLocationStrategy工作...但它不...使用节点精简版服务器 – Mames