Route mismatch

It's showing an error message saying it can't match any routes, but I have clearly defined the route I'm using here:

  {
    path: 'categories',
    component: CategoriesComponent,
  },
  {
    path: 'categories/:id',
    component: CategoryComponent,
  }

and called it like this:

  edit(id: number){
    this.router.navigate(['/', id]);
  }

The edit() function is linked to a button.

I'm not sure what mistake I'm making, but I keep getting this error:

core.mjs:6485 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: '9'
Error: Cannot match any routes. URL Segment: '9'

However, when I manually redirect the URL to:

http://localhost:4200/dashboard/categories/9

it works perfectly fine. I feel like I must be missing something obvious, but for the life of me, I can't figure out where my mistake is hiding.

Please save me the time it will take to find the error.

I'm still new to Angular.

Answer №1

If it is appropriate, you can utilize the method relativeTo:

edit(id: number) {
  this.router.navigate(['/', id], { relativeTo: this.route });
}

Alternatively, you can explicitly indicate the route to navigate to using /categories:

edit(id: number) {
  this.router.navigate(['/categories', id]);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue: The AndroidManifest.xml file requires a valid Facebook app id to be configured

I followed the instructions in this helpful video. The app installed successfully on my Xiaomi Redmi 4A device, but unfortunately, I encountered an error when trying to use Facebook within the code. Error: When syncing the application org.nativescript. ...

Use the jqwidgets jxGrid with the checkbox selection mode to enable row selection by checking for any clicks on the row

Currently, I am using a jqxGrid that contains checkboxes. I would like the ability for users to select a row by clicking on any part or column of the row, not just on the checkbox itself. Unfortunately, it seems this feature is not directly supported. Has ...

Is there a sweet TypeScript class constructor that can take in its own instance as an argument?

I have a scenario where I need to read in instances of Todo from a CSV file. The issue is that Papaparse does not handle dynamic conversion on dates, so I'm currently dropping the object into its own constructor to do the conversion: class Todo { ...

The '&&' operator cannot be used with method groups in the tst file

I am currently facing an issue while trying to verify a condition in the tst (typescript generator) file within my C# application. The error message I am encountering states that the Operator '&&' cannot be applied to operands of type 'metho ...

How to insert a row above the header in an Excel sheet using JavaScript within

i am using excel js to export json data to excel. The json data is successfully exported to the sheet, but now I need to add a row that provides details of the sheet above the header text. for more details please refer image the code is shown below: i ...

Is there a way to restrict the use of `any` exclusively to the tests folder when working with biome

I am currently working on a TypeScript repository that has both a 'src' and 'tests' folder. My goal is to set up biome for this project. Specifically, I want to enforce strict linting rules in the 'src' folder, but allow the u ...

How can I set a document ID as a variable in Firebase Firestore?

I recently set up a firestore collection and successfully added data (documents) to it. Firestore conveniently generates unique document ids for each entry. Inserting Data this.afs.collection('questions').add({ 'question': message, &a ...

Encountering "Undefined error" while using @ViewChildren in Angular Typescript

In my application, I am facing an issue with a mat-table that displays data related to Groups. The table fetches more than 50 rows of group information from a data source, but initially only loads the first 14 rows until the user starts scrolling down. Alo ...

Creating type definitions in TypeScript for an object received from an API with an unknown data type, and attempting to enforce specific types on it

Currently in the process of learning TypeScript, so please bear with me if I am not describing this accurately. I have a function that retrieves some data and returns a nested object. I then iterate over this object using forEach method. Although I have d ...

Receiving a 400 Error when Angular HttpClient sends a Set<> to a SpringBoot API endpoint

Currently, I have an endpoint set up to accept a Set<> as a @RequestBody in the following manner: public @ResponseBody ResponseEntity<Response> addTeamOwner(@RequestParam("teamName") String teamName, @RequestBody Set<String> emails, HttpS ...

Navigate to a different directory within Cypress by utilizing the cy.exec() function

Dealing with cypress to execute a python script in another directory. However, it seems like the directory change is not functioning as expected. visitPythonProject() { cy.exec("cd /Users/**/Desktop/project/"); cy.exec("ls"); // thi ...

How can you utilize a component's variable within the method of another component in Angular?

To illustrate my issue, I will provide only the necessary portions of code. My application consists of two components: filter and details. Within the HTML file of the filter component, there is a button that invokes a function from the details component u ...

Utilize Cordova plugins seamlessly within Ionic 2 TypeScript components

I'm currently working on developing a new Ionic2 typescript application. Unfortunately, some of the necessary native access plugins are not yet available in ionic native (such as Routed device check plugin and Read SMS plugins). Therefore, I am in nee ...

Unable to import Express in Angular

In my Angular app, there are no syntax errors present. Within a file titled test1.js, I have only one line of code: var express = require('express'); However, I am encountering an error in my log: (Interestingly, commenting out this single l ...

What is preventing me from using TSC's watch feature?

These are the current versions of my TypeScript and tsc: > npm list typescript -g └── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d09040d180e1e0f140d4c534a5348">[email protected]</a> > tsc -v Ver ...

How can you modify the encapsulation of a third-party component in an Angular application?

Utilizing AngularElements with native encapsulation allows bs4 components to be used in a bs3 project. For example: @Component({ selector: 'app-my-button', templateUrl: './my-button.component.html', encapsulation: ViewEncapsulati ...

What is the method for utilizing an alias at the top within a subquery?

Is it possible to use an alias from the top query in a subquery? I am currently encountering an error with 'artc'. let myQuery = this.articles.createQueryBuilder('artc') .select(['artc.title']) .addSelect(qb => ...

When Using TypeScript with Serverless, 'this' Becomes Undefined When Private Methods are Called from Public Methods

Currently, I am working on constructing an AWS Serverless function using TypeScript. My focus is on creating an abstract class with a single public method that invokes some private methods. Below is the simplified version of my TypeScript class: export ...

The ngOnInit method of Ionic 4 is not executed following a navigation event

Hello, I am currently in the process of learning Ionic Angular and following a tutorial to enhance my skills. Just to give you some context, let's consider two pages: A and B. Below is the code snippet for page B: pageB.ts import { Component, OnIn ...

The separator falls short of spanning the entire width of the page

For some reason, I can't seem to make the divider extend to the full length of the page. <TableRow> <TableCell className={classes.tableCell} colSpan={6}> <Box display="grid" gridTemplateColumn ...