我定义了诸如以下我的路线: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