Problems with this.router.navigate

Asked

Viewed 306 times

-1

Hello, my problem is this, I need to leave the dynamic whenever I play a different value in navigation, this is my code:

editarForm() {
const valor = ('X');
this.router.navigate(['/' + valor + '/edit/'], { relativeTo: this.route });

}

when I throw any "value" in this function the result is the below:

core.js:15723 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'edit'

Error: Cannot match any Routes. URL Segment: 'Edit' At Applyredirects.push.. /node_modules/@angular/router/fesm5/router.js.Applyredirects.noMatchError (router.js:2469) At Catchsubscriber.selector (router.js:2450) At Catchsubscriber.push.. /node_modules/rxjs/_esm5/Internal/Operators/catchError.js.Catchsubscriber.error (catchError.js:34) At Mapsubscriber.push.. /node_modules/rxjs/_esm5/Internal/Subscriber.js.Subscriber. _error (Subscriber.js:80) At Mapsubscriber.push.. /node_modules/rxjs/_esm5/Internal/Subscriber.js.Subscriber.error (Subscriber.js:60) At Mapsubscriber.push.. /node_modules/rxjs/_esm5/Internal/Subscriber.js.Subscriber. _error (Subscriber.js:80) At Mapsubscriber.push.. /node_modules/rxjs/_esm5/Internal/Subscriber.js.Subscriber.error (Subscriber.js:60) At Mapsubscriber.push.. /node_modules/rxjs/_esm5/Internal/Subscriber.js.Subscriber. _error (Subscriber.js:80) At Mapsubscriber.push.. /node_modules/rxjs/_esm5/Internal/Subscriber.js.Subscriber.error (Subscriber.js:60) At tapsubscriber.push.. /node_modules/rxjs/_esm5/Internal/Operators/tap.js.Tapsubscriber. _error (tap.js:61) resolveat Promise (zone.js:831) resolveat Promise (zone.js:788) at zone.js:892 At Zonedelegate.push.. /node_modules/zone.js/dist/zone.js.Zonedelegate.invokeTask (zone.js:423) At Object.onInvokeTask (core.js:17289) At Zonedelegate.push.. /node_modules/zone.js/dist/zone.js.Zonedelegate.invokeTask (zone.js:422) At Zone.push.. /node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195) drainat IcroTaskQueue (zone.js:601) at Zonetask.push.. /node_modules/zone.js/dist/zone.js.Zonetask.invokeTask [as invoke] (zone.js:502) at invokeTask (zone.js:1744)

On the front to understand the idea is the following: inserir a descrição da imagem aqui

  • By error the problem does not seem to be in the variable, 2 things: use template strings to make the code more readable /${valor}/edit, and try to put a url that exists to see if the page is loaded.

1 answer

0

You need to configure the routes in your route module.

In the module:

{
     path: 'edit/:valor',
     component: SeuComponent,
},

In TS:

this.router.navigate(['edit', valor], { relativeTo: this.route.parent });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.