How to Remove Hash from URL in Angular?

By Hardik Savani May 2, 2024 Category : Angular

Hi,

Here, i will show you how to works how to remove hash from url in angular. This article will give you simple example of angular remove hash prefix. We will use angular remove hash from url. you will learn angular routing remove hash (#) on url.

I will give you one solution how to remove hash from url in angular application. we will use useHash make true. you can use this example with in angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17 version app.

Let's see both solution:

Solution:

imports: [

...

RouterModule.forRoot(routes, { useHash: true }) // remove second argument

]

Remove useHash: true from router modules, By default it's false. let's add add bellow:

src/app/app-routing.module.ts

import { NgModule } from '@angular/core';

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

import { HomeComponent } from './home/home.component';

import { UserComponent } from './user/user.component';

const routes: Routes = [

{ path: 'home', component: HomeComponent },

{ path: 'user', component: UserComponent },

];

@NgModule({

imports: [RouterModule.forRoot(routes)],

exports: [RouterModule]

})

export class AppRoutingModule { }

you can try it now...

Tags :
Shares