简体   繁体   English

Angular 2路由在某些页面上禁用导航栏链接

[英]Angular 2 route disable navbar links on some pages

So I have a strange problem. 所以我有一个奇怪的问题。 This is my routing file (without the imports): 这是我的路由文件(没有导入):

export var Routes = {
    home:           new Route({ path: '/',                  name: 'Home', component: Home }),
    photos:         new Route({ path: '/photos',            name: 'Photos', component: Photos }),
    albums:         new Route({ path: '/albums',            name: 'Albums', component: Albums }),
    account:        new Route({ path: '/account/...',       name: 'Account', component: Account }),
    albumPhotos:    new Route({ path: '/albums/:id/photos', name: 'AlbumPhotos', component: AlbumPhotos }),

    login:          new Route({ path: '/account/login',     name: 'Login', component: Login }),
    register:       new Route({ path: '/account/register',  name: 'Register', component: Register }),

    joke:           new Route({ path: '/joke',              name: 'Joke', component: Joke  }),
    team:           new Route({ path: '/team/',             name: 'Team', component: Team  }), 
    editTeam:       new Route({ path: '/team/:id',          name: 'EditTeam', component: EditTeam  }), 
    match:          new Route({ path: '/match/',            name: 'Match', component: Match  }),
    editMatch:      new Route({ path: '/match/:id',         name: 'EditMatch', component: EditMatch  }),
    detailMatch:    new Route({ path: '/detail/:id',        name: 'DetailMatch', component: DetailMatch  }),
    bet:            new Route({ path: '/bet',               name: 'Bet', component: Bet }), 
    editBet:        new Route({ path: '/bet/:id',           name: 'EditBet', component: EditBet  }),
    placeBet:       new Route({ path: '/bet/match/:id',     name: 'PlaceBet', component: PlaceBet  }),
    users:          new Route({ path: '/account/users',     name: 'Users', component: Users }) 

};

export const APP_ROUTES = Object.keys(Routes).map(r => Routes[r]);

This works fine on all pages except for the login and registration pages. 在登录页面和注册页面之外的所有页面上都可以正常工作。 When I go to the login page, the link to login still works, but the link to register is disabled. 当我进入登录页面时,登录链接仍然有效,但是注册链接被禁用。

Here is a html snippet from the navbar: 这是来自导航栏的html代码段:

<li *ngIf="!isUserLoggedIn()">
  <a [routerLink]="[routes.login.name]"><i class="fa fa-unlock-alt fa-fw"></i>&nbsp;Logg inn</a>
</li>
<li *ngIf="!isUserLoggedIn()">
  <a [routerLink]="[routes.register.name]"><i class="fa fa-unlock-alt fa-fw"></i>&nbsp;Register deg</a>
</li>

If I go to the registration page, both the link to login and to register is disabled... 如果我转到注册页面,则登录和注册链接都被禁用...

What is going on? 到底是怎么回事?

      You are going correct just you change your routerLink in Html 

      For Eg:

       export var Routes = {
           photos: new Route({ path: '/photos', **name:'Photos'**,component:Photos }),
       };

      // Html For This /name of component
        <li *ngIf="!isUserLoggedIn()">
                    <a [routerLink]="['/Photos']"><i class="fa fa-unlock-alt fa-fw"></i>&nbsp;Logg inn</a>
        </li>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM