Issue: Unable to find a matching route in Angular 7

Hey there! I'm struggling with setting up the routing in my Angular app. I keep encountering the error 'Cannot match any routes', which makes me think that something is misconfigured.

I'm attempting to create a functionality where clicking on a person's name from a table will navigate the user to a new route (detail/ID) displaying that individual's information.

Below is the code snippet:

Runner-list.HTML - Where the user can click on the name

<h2 class="text-center">{{title}}</h2>
<div class="container">
  <table class="table table-striped">
    <thead class="thead-dark">
    <tr>
      <th scope="col">Runner Name</th>
      <th scope="col">UKAN Number</th>
    </tr>
    </thead>
    <tbody>
    <tr *ngFor="let runner of myRunners | paginate: {itemsPerPage: 10, currentPage: p }">
      <td><a routerLink="/detail/{{runner.RunnerUKAN}}">{{runner.RunnerName}}</a></td>
      <td>{{runner.RunnerUKAN}}</td>
    </tr>
    </tbody>
  </table>
  <pagination-controls class="text-center" (pageChange)="p = $event"></pagination-controls>
</div>

app-routing module

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RunnerDetailsComponent} from './runner-details/runner-details.component';
import {RouterModule, Routes} from '@angular/router';

const routes: Routes = [
  { path: 'detail:/id', component: RunnerDetailsComponent }
];

@NgModule({
  declarations: [],
  imports: [
    CommonModule,
    RouterModule.forRoot(routes)
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }

Runner Details ts file (The information shown upon clicking)

import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {Location} from '@angular/common';

import {RunnersService} from '../model/runners.service';

@Component({
  selector: 'app-runner-details',
  templateUrl: './runner-details.component.html',
  styleUrls: ['./runner-details.component.css']
})
export class RunnerDetailsComponent implements OnInit {

  Runner: any;

  constructor(
    private route: ActivatedRoute,
    private RuService: RunnersService,
    private location: Location
  ) { }

  getHero() {
    const id = +this.route.snapshot.paramMap.get('detail');
    this.RuService.getRun(id).subscribe(runner => this.Runner = runner);
  }

  getRunner(id) {
    this.RuService.getRun(id).subscribe(runner => this.Runner = runner);
  }

  ngOnInit() {
    this.getHero();
  }

}

If you require any other file, please let me know.

Thank you for any assistance!

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

Error when compiling TypeScript: The callback function provided in Array.map is not callable

This is a Node.js API that has been written in Typescript. app.post('/photos/upload', upload.array('photos', 12), async (req, res) => { var response = { } var list = [] try { const col = await loadCollection(COLLECTION_NAM ...

An automatic conversion cannot handle spaces and prohibited characters in Object keys

The AlphaVantage API uses spaces and periods in the keys. Their API documentation is not formal, but you can find it in their demo URL. In my Typescript application, I have created data structures for this purpose (feel free to use them once we solve the ...

Looking for a solution to resolve the issue "ERROR TypeError: Cannot set property 'id' of undefined"?

Whenever I attempt to call getHistoryData() from the HTML, an error message "ERROR TypeError: Cannot set property 'id' of undefined" appears. export class Data { id : string ; fromTime : any ; toTime : any ; deviceType : string ...

What is the best way to retrieve a value from async/await functions?

async function fetchNetworkStatus() { const network = await Network.getConnection(); setConnection(network.isConnected); console.log(connectionStatus); if (network.isConnected) { return true; } else { ...

Error message: Invalid input for directive, only numeric values are accepted

I need help with a directive that restricts non-numeric symbols in an input field. Below is the code for the directive: import { NgControl } from "@angular/forms"; import { HostListener, Directive } from "@angular/core"; @Direct ...

Securing the core operational intelligence within web services

How can I prevent a hacker from reverse engineering the business logic of my webservice in order to copy my software logic? Are there any methods available to protect this sensitive information? I am utilizing the .NET ASP.NET and C# development platform ...

When employing a string union, property 'X' exhibits incompatibility among its types

In my code, I have two components defined as shown below: const GridCell = <T extends keyof FormValue>( props: GridCellProps<T>, ) => { .... } const GridRow = <T extends keyof FormValue>(props: GridRowProps<T>) => { ... & ...

An easy method to define argument types for every function type in TypeScript

How can I assign argument types to each function type in TypeScript? Each function has a parameter associated with it. [Example] type F1 = (arg: number) => void; type F2 = (arg: string) => void; const caller = (f: F1 | F2) => (n: number | strin ...

Guide to Automatically Updating Angular Component When Service Data Changes

I am currently working on an Angular application that features a sidebar component displaying different menu items based on the user's data. The sidebar should only display an option for "Empresas" if the user has not created any company yet. Once a c ...

Identifying JavaScript Errors in a Web Page: A Guide to Cypress

Currently, I am working on creating a spec file that contains N it(s), with each it visiting a specific page within the application and returning the number of errors/warnings present. I have also shared my query here: https://github.com/cypress-io/cypres ...

Taking in user inputs using Angular 8 reactive forms

My goal is to make my forms function as intended, with multiple forms on each product item having an update and delete option. However, I encountered an issue when adding the [formGroup]="profileForm" directive - the form controls stopped working. This was ...

Can classes be encapsulated within a NgModule in Angular 2/4?

Looking to organize my classes by creating a module where I can easily import them like a separate package. Take a look at this example: human.ts (my class file) export class Human { private numOfLegs: Number; constructor() { this.numOfLegs = 2 ...

Encountering an error message in Angular stating "Spotify is not defined" while utilizing "@types/spotify-web-playback-sdk"

I'm currently integrating Spotify's web player SDK into an Angular project. I followed the steps outlined in this particular question and answer: Installing the types package, then including the types reference at the beginning of the file where ...

Checking the response data using an Angular interceptor

As a beginner in AngularJS, I am looking for a way to intercept all $http requests and redirect to the login page if the response data indicates a 401 error. I would greatly appreciate any assistance with this issue. Thank you! ...

Can you explain the distinction between "parser" and "parserOptions.parser" in an ESLint configuration?

For a considerable amount of time, I have been using the TypeScript and Vue presets provided below. While it has been functional, I realize that I do not fully comprehend each option and therefore seek to gain a better understanding. Firstly, what sets apa ...

Discover the data type without using the extends keyword within an interface in Typescript

I'm struggling with making my code declarative enough. I want to infer a type inside an interface scope and then use that same type as an argument for a method within the interface. Here is a simple example: interface Prop { x: infer U, // ^^ ...

Having trouble iterating over an array in Angular's TypeScript

I've been attempting to loop through an array of objects in TypeScript, but encountered the following error: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'forEach' of undefined TypeError: Cannot read property 'fo ...

Angular keeps FormArray elements' validity up-to-date as new elements are added to the array

I am facing an issue where I do not want the validators to run unnecessarily. Every element of FormArray is being validated asynchronously, so I prefer the validators to be triggered only when the control's value actually changes. It seems odd that va ...

Error in web services: reflection of method is not possible

When attempting to instantiate a service, I encounter an "Method cannot be reflected" error. delving further into the inner exceptions reveals: "Types 'WebServiceClient.com.compamy.string1' and 'WebServiceClient.com.company.string& ...

Trigger functions on a universal component from the nested component

I am currently working on an Angular project with two components, one being a generic component where the table is defined and the other being a component that invokes this table by passing the required data. However, I encountered an issue where the tabl ...