Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法导航到ID为的路线_Angular_Typescript_Angular5_Angular Routing - Fatal编程技术网

Angular 无法导航到ID为的路线

Angular 无法导航到ID为的路线,angular,typescript,angular5,angular-routing,Angular,Typescript,Angular5,Angular Routing,使用路由器时,我无法导航到ID参数为的路由 在我的组件中使用此代码 import { Router } from '@angular/router'; ... constructor(private router: Router) { } ... public create() { ... this.router.navigate(['/category/edit', id]); } 导致错误 Error: Cannot match any routes. URL Segmen

使用路由器时,我无法导航到ID参数为的路由

在我的组件中使用此代码

import { Router } from '@angular/router';
...
constructor(private router: Router) { }
...
public create() {
    ...
    this.router.navigate(['/category/edit', id]);
}
导致错误

Error: Cannot match any routes. URL Segment: 'category/edit;id=11'
    at ApplyRedirects.noMatchError (router.js:1719)
    at CatchSubscriber.eval [as selector] (router.js:1684)
    at CatchSubscriber.error (catchError.js:105)
    at MapSubscriber.Subscriber._error (Subscriber.js:131)
    at MapSubscriber.Subscriber.error (Subscriber.js:105)
    at MapSubscriber.Subscriber._error (Subscriber.js:131)
    at MapSubscriber.Subscriber.error (Subscriber.js:105)
    at MapSubscriber.Subscriber._error (Subscriber.js:131)
    at MapSubscriber.Subscriber.error (Subscriber.js:105)
    at LastSubscriber.Subscriber._error (Subscriber.js:131)
    at ApplyRedirects.noMatchError (router.js:1719)
    at CatchSubscriber.eval [as selector] (router.js:1684)
    at CatchSubscriber.error (catchError.js:105)
    at MapSubscriber.Subscriber._error (Subscriber.js:131)
    at MapSubscriber.Subscriber.error (Subscriber.js:105)
    at MapSubscriber.Subscriber._error (Subscriber.js:131)
    at MapSubscriber.Subscriber.error (Subscriber.js:105)
    at MapSubscriber.Subscriber._error (Subscriber.js:131)
    at MapSubscriber.Subscriber.error (Subscriber.js:105)
    at LastSubscriber.Subscriber._error (Subscriber.js:131)
    at resolvePromise (zone.js:809)
    at resolvePromise (zone.js:775)
    at eval (zone.js:858)
    at ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4724)
    at ZoneDelegate.invokeTask (zone.js:420)
    at Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)
    at ZoneTask.invokeTask [as invoke] (zone.js:500)
    at invokeTask (zone.js:1517)
如果在模板中使用它,效果很好


{{category.name}
{{category.code}}
编辑
这是我的路线定义

{
    path: 'category/edit/:id',
    component: EditComponent,
    resolve: {
        model: CategoryResolver
    }
}
尝试使用和不使用解析器,但两种方式都不起作用


我正在使用Angular 5.2.0CLI 1.6.5此.router.navigate(['/category/edit',id])的
结果是<代码>类别/编辑;id=11
。当您传入对象而不是字符串时,将使用查询参数(如
;id=11
)。我假设变量
id
的类型是object而不是string

id:Object={id:'11'};
应改为

id:string='11';

您是否有简单的打字错误?URL为
category/edit;id=11
,但这与路由定义
category/edit/:id
不匹配,因为URL中
edit
之后没有正斜杠。在这个.router.navigate之前的id.what console.log(['..给出?@Brandon,如果使用
['category/edit',category.id]
从模板中可以工作。如果使用路由器导航,则不起作用。当我将导航更改为
this.router.navigate(['category/edit/:id',id])
时,它确实起作用。但是我的新浏览器位置类似于“../category/edit/:id;id=11”。@Vega控制台输出为{id:13}。似乎这不是我期望的。我期望的是一个可观察的对象,但实际值是一个对象{id:11}。按照您的建议更改了我的代码,现在它可以工作了!