Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular removes directory in url when routing

Tags:

angular

I set up a local IIS and a application with a directory called test:

enter image description here

Then in my browser I browse to: "http://localhost/test"

I have a route for this:

const routes: Routes = [
 { 
  path: '', pathMatch: 'full', component: LoginComponent 
 },
 { 
  path: '**', redirectTo: '' 
 }
];

 @NgModule({
    imports: [
       RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
    ],
    exports: [RouterModule]
 })

 export class AppRoutingModule {}

But when I arrive at the login page, the browser removes the "test" and just does the "http://localhost/" in the browsers address, which is wrong.

The browser also don't get the assets now as "test" is missing: enter image description here Just for information, when I build the app, I build it with --baseHref=/test/

like image 961
Michael Winther Avatar asked Nov 07 '22 07:11

Michael Winther


1 Answers

you set it to redirect to blank if there is no matching route, and there is not one for test...

guessing you want to set the base href in your build command...

ng build --prod --baseHref=test

docs: https://angular.io/cli/build

you can set the same in ng serve if you're trying to run this as a dev server. but that seems redundant.

like image 197
bryan60 Avatar answered Nov 15 '22 12:11

bryan60