How do I extend RouterOutlet when using the new router in RC.1

后端 未结 2 1519
耶瑟儿~
耶瑟儿~ 2021-01-05 16:49

I can\'t seem to extend RouterOutlet when using the new router in RC.1

Example:

import { Directive } from \'@angular/core\';
import { Router, ROUTER_         


        
2条回答
  •  离开以前
    2021-01-05 17:35

    Here is working code with version RC 1

    import { Directive, Attribute, ViewContainerRef, DynamicComponentLoader } from '@angular/core';
    import { Router, Routes, RouterOutletMap } from '@angular/router';
    import { RouterOutlet } from '@angular/router/src/directives/router_outlet';
    
    @Directive({
        selector: 'router-outlet'
    })
    export class LoggedInRouterOutlet extends RouterOutlet {
    
        constructor(parentOutletMap: RouterOutletMap, _location: ViewContainerRef, name: string){
            super(parentOutletMap, _location, name);
    
        }
        //activate() {} //EXPIRED
        unload(): void { }
        loadedComponent: Object
        isLoaded: boolean
        load(factory, providers, outletMap: RouterOutletMap): any {
            super.load(factory, providers, outletMap);
            //DO YOUR CHECK HERE
            return this.loadedComponent;
        }
    }
    

提交回复
热议问题