2016-02-09 62 views
1

我對Angular 2非常新穎。我對路由有疑問,實際上我不明白爲什麼會發生這種情況。Angular 2 - 刷新時的路由行爲

@Component({ 
    selector: 'app', 
    templateUrl: 'app/app.template.html', 
    directives: [ROUTER_DIRECTIVES] 
}) 
@RouteConfig([ 
    {path:'/index', name:'Index', component: IndexComponent, useAsDefault: true}, 
    {path:'/home', name: 'Home', component: HomeComponent} 
]) 
export class AppComponent { } 

IndexComponent我有一個具有以下屬性的按鈕:[routerLink]="['Home']"

所以,當我按下它時,HomeComponent出現,因爲它是supossed發生。按照預期,URL從http://localhost/index更改爲http://localhost/home

問題是,如果現在我刷新瀏覽器,它將URL更改爲http://localhost/home/index,並向我顯示索引模板。如果我再次刷新瀏覽器會引發錯誤。

我沒有讀太多內容,但我猜我不能刷新頁面/home,因爲Angular 2無法知道要帶我去哪裏。我對嗎?如果他刷新瀏覽器,我應該怎麼做才能讓用戶訪問/index

回答