我有一個非常簡單的應用程序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