Angular 2 routes not working after building the project

Viewed 6760

These are my routes:

import { Routes } from '@angular/router';
import {WelcomeComponent} from "./welcome/welcome.component";
import { LoginComponent } from './login/login.component';

export const routes: Routes = [
  {path: '', component: WelcomeComponent},
  {path: 'login', component: LoginComponent},
  {path: '**', component: WelcomeComponent}
];

I buid my project using ng buid.

When I enter a not defined path, I expect the application to redirect to '/' path as it happens during development, but I get an 404 Error.

I get the same error even when I manually enter /login URL.

What am I missing?

4 Answers

For me the problem was fixed when I changed the build command from ng build to ng build --prod. Ofcourse you cannot use this solution when you need the build to function outside of the production environment.

Related