'url 404 with I go in a specificy url

I have a web app and when I go on :

    http://localhost:8080/Test/home
http://localhost:8080/Test/login

It gives me 404, and it doesn't me the home

My app-routing.ts is:

const routes: Routes = [
  {
    path: environment.URL_LOGIN_ROUTING, loadChildren: () => import("./components/login/login.module").then(m =>
      m.LoginModule)
  },
  {
    path: environment.URL_HOME_ROUTING, component: HomeComponent, canActivate: [AuthGuard]
  },
  {path: '', redirectTo: environment.URL_LOGIN_ROUTING, pathMatch: 'full' }
  
];

in My envinroment is:

//ROUTING
const URL_LOGIN_ROUTING = "/login";
const URL_HOME_ROUTING = "/home";
export const environment = {

  //DA INSERIRE NEL ROUTING
  URL_LOGIN_ROUTING: URL_LOGIN_ROUTING,
   URL_HOME_ROUTING: URL_HOME_ROUTING,

};

I start angular with:

ng build --watch --base-href /Test/

I I go on http://localhost:8080/Test/ it work but if I go on http://localhost:8080/Test/login or

http://localhost:8080/Test/home

it gives me 404. Anyone can help me?



Solution 1:[1]

Remove the preceeding / from your paths. You should never need a preceeding or a trailing / when dealing with angular Router.

const URL_LOGIN_ROUTING = "login";
const URL_HOME_ROUTING = "home";

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris Hamilton