I have this router:
import { Route, RouterModule } from '@angular/router';
import { ProjectDetailsComponent } from '../components/project-details/project-details.component';
export const ROUTES: Route[] = [
{
path: '',
redirectTo: '/details',
pathMatch: 'full'
},
{
path: 'details/:id',
component: ProjectDetailsComponent
}
];
Also I have an appropriate controller, named ProjectDetailsComponent.
This is my app module, in which I have registered my routes:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
// Custom components
import { AppComponent } from './app.component';
import { ProjectDetailsComponent } from './components/project-details/project-details.component';
// Routes
import { ROUTES } from './services/router';
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot(ROUTES, { useHash: true })
],
declarations: [AppComponent, ProjectDetailsComponent],
bootstrap: [AppComponent]
})
export class AppModule {
}
And its my app.component, in which I try to redirect to ProjectDetailsComponent using "/details" routes and send to it project id:
import { Component, OnInit } from '@angular/core';
import { IProject } from './domain/projects
import { Router } from '@angular/router';
// Routes
import { ROUTES } from './services/router';
@Component({
selector: 'projects-app',
templateUrl: 'app/app.component.html'
})
export class AppComponent implements AfterViewInit {
public activeProject: IProject;
public projects: Array<IProject>;
constructor(public router: Router) {
}
ngOnInit() {
this.router.navigate(['/details', this.activeProject.Id]);
}
}
But when I try to navigate to 'details/:id' router I get following error:
C:\Sources\SolarPro\build\debug\resources\app\node_modules\@angular\core\bundles\core.umd.js:3521 EXCEPTION: Uncaught (in promise):
Error: Cannot match any routes. URL Segment: 'details'
Please help me with my problem.
<server_url>/details/1does it work?window.location.assing()it doesn't work as expected. But if I usethis.router.navigateByUrl("/app/details/1");I get the previous error.