Router directives in two places for same purpose

前端 未结 1 977
耶瑟儿~
耶瑟儿~ 2021-01-25 20:05

I am having a bit of trouble understanding the logic here

root-component

import { Component } from \"angular2/core\";
import { TopNavigationComponent } f         


        
相关标签:
1条回答
  • 2021-01-25 20:34

    As @Bhavik said ROUTER_DIRECTIVES is required everytime you use RouterLink or RouterOutlet (you can specify each one of them as well).

    Check the source code for Router

    export const ROUTER_DIRECTIVES: any[] = CONST_EXPR([RouterOutlet, RouterLink]);
    

    Obviously adding it everytime you're using either of one of them is annoying, so you can make it simpler by using PLATFORM_DIRECTIVES. This way you'll add it once in your application and it will be available across of it.

    bootstrap(App, [
        provide(PLATFORM_DIRECTIVES, {useValue: [ROUTER_DIRECTIVES], multi: true})
    ]);
    

    Note that there's an issue open proposing to add ROUTER_DIRECTIVES to ROUTER_PROVIDERS, so we can even skip the solution suggested above. That would make setting up Router much easier.

    0 讨论(0)
提交回复
热议问题