auth0-blog / angular2-authentication-sample

This is a sample that shows how to add authentication to an Angular 2 (ng2) app
MIT License
966 stars 334 forks source link

Router: ORIGINAL EXCEPTION: Primary outlet is already registered. #63

Open greg-md opened 8 years ago

greg-md commented 8 years ago

Why in 2.0.0-beta.17 I can not use anymore custom layouts for router-outlet? I get an error if I want to change the layout in application. For example:

<div class="guest-layout" *ngIf="auth.isGuest">
    <router-outlet></router-outlet>
</div>

<div class="member-layout" *ngIf="auth.isMember">
    <router-outlet></router-outlet>
</div>

When they should change, I get:

angular2.dev.js?v=1.0.0:25644 Error: Primary outlet is already registered.
    at new BaseException (angular2.dev.js?v=1.0.0:5496)
    at e.t.registerPrimaryOutlet (router.min.js?v=1.0.0:3)
    at RouterDirective.t (router.min.js?v=1.0.0:2)
    at new RouterDirective (router.js:26)

Maybe there are another ways of doing this?

marcusdb commented 8 years ago

Same issue here, solved by the code below

import { ROUTER_DIRECTIVES } from '@angular/router-deprecated';
import {RouterOutlet} from '@angular/router-deprecated';
....
// when using ROUTER_DIRECTIVES apply the filter
ROUTER_DIRECTIVES.filter(direc => direc != RouterOutlet)