Router directives in two places for same purpose

一个人想着一个人 提交于 2019-12-02 06:14:19

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!