Issue: I am currently setting up routes for my application, aiming to structure the URL as https://localhost:4200/hero=id, where the 'id' will be dynamically selected. However, this setup is not functioning as expected.
If I attempt to use a URL with the path /hero/:id as recommended in Angular documentation, it works perfectly.
https://localhost:4200/hero/:id
I require assistance in finding a solution to this dilemma.
Below is an excerpt from my route configuration file:
const appRoutes: Routes = [
{ path: 'hero', component: HeroesComponent },
{path: 'hero{=:id}', component: HeroDetailComponent},
{
path: 'home',
redirectTo: '/hero',
data: { title: 'Heroes List' }
},{
path: 'student',
component: AppTable
},{
path: 'video',
component: VideoTagComponent
},{ path: '',
redirectTo: '/hero',
pathMatch: 'full'
}
// { path: '**', component: PageNotFoundComponent }
];
Additionally, here is a snippet of my HeroesComponent file demonstrating how I'm routing to path = "/hero="+id:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import {Hero} from './hero';
// Array of hero objects
const HEROES: Hero[] = [
...
];
@Component({
selector: 'my-heroes',
templateUrl: './heroes.html',
styleUrls: ['./app.component.css']
})
export class HeroesComponent {
...
}
Upon inspection, I've encountered the following error in the browser console:
core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'hero%3D13'
Error: Cannot match any routes. URL Segment: 'hero%3D13'