我定義了諸如以下我的路線:Angular2混編版網址獲取當前url
const appRoutes: Routes = [
{
path: 'auth',
component: AuthenticationComponent,
},
{
path: '',
component: HomeComponent,
canActivate:[AuthenticationGuard],
children:[
{
path: 'list',
component: TaskListComponent,
canActivate:[AuthenticationGuard]
},
{
path: 'create',
component: CreateTaskComponent,
canActivate:[AuthenticationGuard]
},
{
path: 'profile',
component: ProfileComponent,
canActivate:[AuthenticationGuard]
},
{
path: 'agreement',
component: UserAgreementComponent,
canActivate:[AuthenticationGuard]
},
]
},
];
我瀏覽他們喜歡以下:
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#/list">List</a>
<a class="mdl-navigation__link" href="#/create">Create</a>
<a class="mdl-navigation__link" href="#/profile">Profile <span *ngIf="profileNotPresent" mdl-badge="Start"></span> </a>
<button class="mdl-button mdl-js-button" (click)="logout()">
<i class="material-icons">exit_to_app</i>
</button>
</nav>
我不得不添加哈希,因爲當我部署的應用程序它開始拋出我的路線404錯誤。隨着哈希網址它的作品。
但是在我的代碼我有我在那裏顯示的條件下,是真實的,如果它是基本路線股利的條件:
if(this.router.url == '/'){
this.showHomeContent=true;
}
那個時候沒有哈希我的網址是「/」,「/配置文件'等,它用來正確工作。現在他們是'#','#/ profile'等等,並且這個條件不再起作用,導致特定的div始終保持打開狀態。
我該如何解決這個問題?
只是添加散列工作? '==#/' – DeborahK