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

查看:78
本文介绍了在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"类型不是构造函数类型,并且激活部分也不起作用.我想念什么吗?

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.

提示

也就是说,新的路由器工作仍在进行中.如果您当前正在尝试从Beta路由器或@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天全站免登陆