Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

421
Visualizações
angular 4: routing behavior after build --prod

I have an issue with routing when I build my app with ng build --prod. The router.config doesn't register these routes only in prod environment.

error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'myvehicle'↵Error: Cannot match any routes. URL Segment: 'myvehicle'

vehicle-routing.module.ts

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

import { ConfigService } from '../../core/services/config/config.service';
import { VehicleComponent } from './vehicle.component';

const vehicleRoutes: Routes = [];

ConfigService.scope('vehicle').getConfig().map(vehicle => {
  vehicleRoutes.push({
    path: vehicle['informations']['route'],
    component: VehicleComponent,
  });
});

@NgModule({
  imports: [RouterModule.forChild(vehicleRoutes)],
  exports: [RouterModule],
})
export class VehicleRoutingModule { }

export const routedComponents = [VehicleComponent];

header.component.html

<a [routerLink]="[vehicleService.getRoute(vehicle.id)]">...

The routing works when I use the following code instead of the code above:

const vehicleRoutes: Routes = [
  {
    path: "test-a",
    component: VehicleComponent,
  },{
    path: "test-b",
    component: VehicleComponent,
  }
];

I checked the path value and it's the same in the both ways as well as the console.log(vehicleRoutes) output in dev / prod environment.

ps: the path is loaded via an http request because it's based on slug set in the back office.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Please provide the base url in index.html file in base tag

Example :

<base href="https://www.w3schools.com/images/" target="_blank">
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda