Search code examples
angularangular-routing

Why angular routing adds hashtag # to the url


Version Used

Angular version : 7.10 @angular/router": "~7.2.0",

The question is

Why angular adds a hashTag to the url.

Example case:

const routes: Routes = [
  {
    path: 'aktion',
    component: AktionComponent
  }

does match the url

http://localhost:4200/aktion

but does not match the url

http://localhost:4200/#/aktion

Solution

  • In app module, do like this

    @NgModule({
      imports: [
      // other imports
        RouterModule.forRoot(routes, { useHash: true }) //make it false
      ],
      declarations: [
      ],
      providers: [
    
      ],
      bootstrap: [ AppComponent ]
    })
    export class AppModule { }