Angular 5 route problems

1

I have my normal and simple route app.routing.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { LoginComponent } from '../login/login.component';
import { HomeComponent } from '../home/home.component';
import { CursosComponent } from '../cursos/cursos.component';
import { CursoDetalheComponent } from '../cursos/curso-detalhe/curso-detalhe.component';
import { PageNotFoundComponent } from '../page-not-found/page-not-found.component';

const PORTAL_ROUTER: Routes = [
// { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: '', component: HomeComponent },
{ path: 'login', component: LoginComponent },
{ path: 'cursos', component: CursosComponent },
{ path: 'curso/:id', component: CursoDetalheComponent },
{ path: '**', component: PageNotFoundComponent },
];

@NgModule({
  imports: [ RouterModule.forRoot(PORTAL_ROUTER)],
  exports: [ RouterModule ]
})

export class PortalRoutingModule {}

the basic routes work localhost / login or localhost / courses, however, when I visualize the route with parameter, in the case the id, it shows me as follows localhost / courses / course / 1 and of course this will give error, as it would have to show localhost / course / 1, this is correct way

    
asked by anonymous 14.01.2018 / 17:16

1 answer

1

You need to pass the absolute path to the route.

Example redirecting by code:

this.router.navigate(['/curso/1'])

Example redirecting through links:

 <a [routerLink]="/curso/1">Link</a>
    
14.01.2018 / 19:21