Angular 2 - 如何获得当前路线的未解析版本

时间:2016-11-11 01:38:04

标签: angular routing routes

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

ie: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

1 个答案:

答案 0 :(得分:0)

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

Plunker上的代码