【问题标题】:Angular 2 - How can I get an unparsed version of my current routeAngular 2 - 如何获得当前路线的未解析版本
【发布时间】:2016-11-11 01:38:04
【问题描述】:

我想要当前路线的未解析版本

即:dashboard/:id

我不希望 id 部分显示为数字。

这就是我在做的事情

  "dependencies": {
    "@angular/common": "~2.1.0",
    "@angular/compiler": "~2.1.0",
    "@angular/core": "~2.1.0",
    "@angular/forms": "~2.1.0",
    "@angular/http": "~2.1.0",
    "@angular/platform-browser": "~2.1.0",
    "@angular/platform-browser-dynamic": "~2.1.0",
    "@angular/router": "~3.1.0",
    "@ngrx/core": "^1.2.0",
    "@ngrx/store": "^2.2.1",
    "core-js": "^2.4.1",
    "ng2-breadcrumb": "^0.4.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },

尝试浏览 RouterActivatedRoute 并找不到它..

  constructor(
    private activatedRoute: ActivatedRoute,
    private router: Router
  ) {

    console.log(this.activatedRoute.routeConfig.path)
  }

Error in ./AppComponent class AppComponent - inline template:54:2 caused by: Cannot read property 'path' of null

【问题讨论】:

  • 你能上传你的路线配置吗?您在哪个组件中遇到了该错误? @hamobi

标签: angular routing routes


【解决方案1】:

您可以从ActivatedRoute 访问Route,然后使用path 值获取未解析的路由。

Plunker上的代码

【讨论】:

  • 我遇到了一个错误。请看上面。我的路由配置为空
猜你喜欢
  • 2017-07-21
  • 2020-08-04
  • 1970-01-01
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-02
  • 2019-03-01
相关资源
最近更新 更多