在 RC.1 中使用新路由器时如何扩展 RouterOutlet [英] How do I extend RouterOutlet when using the new router in RC.1

查看:16
本文介绍了在 RC.1 中使用新路由器时如何扩展 RouterOutlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 RC.1 中使用新路由器时,我似乎无法扩展 RouterOutlet

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

示例:

import { Directive } from '@angular/core';
import { Router, ROUTER_DIRECTIVES, RouterOutlet } from '@angular/router';


@Directive({
  selector: 'router-outlet'
})

export class RouterOutletDirective extends RouterOutlet {

}

错误:

@angular/router/index"' 没有导出成员 'RouterOutlet'.

@angular/router/index"' has no exported member 'RouterOutlet'.

我做错了什么还是RC.1中的新路由器坏了?

Am i doing something wrong or is this broke with the new router in 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 RouterOutletDirective extends RouterOutlet {

  constructor(parentOutletMap: RouterOutletMap, _location: ViewContainerRef, name: string) {
    super(parentOutletMap, _location, name);
    console.log( parentOutletMap );
  }


  activate() {
    console.log('Activate');
  }
}

所以它现在正在运行,但是 RouterOutlet 用红色下划线标出,类型any"不是构造函数类型,而且 activate 部分也不起作用.我错过了什么吗?

So it's now running but the RouterOutlet is underlined in red with type "any" is not a constructor function type and also the activate part doesn't work. Am i missing something?

推荐答案

RouterOutletRouterLink 不是从 @angular/router 导出的.最近已经修复了这个问题,我希望这个修复程序包含在 RC.2 中.

RouterOutlet and RouterLink are not exported from @angular/router. This was fixed already recently and I'd expect this fix to be included in RC.2.

在新版本发布之前,您可以从私有路径 (src/...) 导入它们作为解决方法.

You can import them from the private path (src/...) as a workaround until the new version is published.

提示

也就是说,还有一个新的路由器正在进行中.如果您目前正在从测试版路由器或 @angular/router-derprecated 迁移到 @angular/router,最好推迟到新的路由器推出.

That said, there is again a new router work in progress. If you currently working on migrating from the beta router or @angular/router-derprecated to @angular/router it's probably better to postpone until the new new router is out.

这篇关于在 RC.1 中使用新路由器时如何扩展 RouterOutlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆