Angular 2+谷歌分析+路由器导航
Angular 2 + google analytics + router navigation
我正试图将谷歌分析添加到我的项目中,但遇到了一些导航错误,我正在使用新的路由器,下面是我的代码:
// app.component.ts
declare var ga:Function;
export class App {
private currentRoute:string;
constructor(_router: Router, _location: Location) {
_router.events.subscribe((event:Event) => {
if(event instanceof NavigationStart) {
var newRoute = this._location.path() || '/';
if(newRoute !== this.currentRoute) {
ga('send', 'pageview', newRoute);
this.currentRoute = newRoute;
}
}
});
}
}
这就是我得到的错误:
ERROR in [default] angular/src/app/app.ts:18:27
Argument of type '(event: Event) => void' is not assignable to parameter of type 'NextObserver<NavigationStart | NavigationEnd | NavigationCancel | NavigationError> | ErrorObserve...'.
Type '(event: Event) => void' is not assignable to type '(value: NavigationStart | NavigationEnd | NavigationCancel | NavigationError) => void'.
Types of parameters 'event' and 'value' are incompatible.
Type 'NavigationStart | NavigationEnd | NavigationCancel | NavigationError' is not assignable to type 'Event'.
Type 'NavigationStart' is not assignable to type 'Event'.
Property 'bubbles' is missing in type 'NavigationStart'.
ERROR in [default] angular/src/app/app.ts:19:23
Cannot find name 'NavigationStart'.
ERROR in [default] angular/src/app/app.ts:20:24
Property '_location' does not exist on type 'App'.
请添加导入语句,看看这是否解决了您的问题:
import {Location} from '@angular/common';
import {NavigationStart} from '@angular/router';
相关文章:
- 父页面的角度路由器导航高亮显示
- 骨干路由器导航和锚定href
- 使用 ui 路由器导航到非默认状态
- React路由器:防止导航到目标路由
- 针对浏览器的不同响应的Backbone.js路由器模式“;背面“;按钮或直接导航
- 可以't使用URL导航到ui路由器状态
- 骨干路由器.导航如何传递动态ID
- 来回导航时删除/取消UI路由器中的动画
- 使用 react 路由器在页面部分内导航
- 有条件地导航到带有角度 ui 路由器的状态
- 主干路由器导航到../#/<路由>而不触发路由器事件.如何
- 将导航选项卡样式类设置为活动,如果当前在该路由中 反应反应路由器.
- 反应路由器导航栏导航
- 使用ui路由器导航到嵌套的命名视图
- React redux connect()'s的mapStateToProps在react路由器导航上被多次调用
- React Redux和Redux -observable在异步操作完成后使用路由器导航到另一个页面
- AngularJS, UI路由器-导航到"foo/bar"去“foo"”
- Angular2不能用路由器导航
- Angular 2+谷歌分析+路由器导航
- 使用骨干路由器导航