How does Angular implement hash mode URLs (that is, the kind of URLs with #, hashtag URLs)

[Method 1] Add useHash to src\app\app-routing.module.ts

@NgModule({

...

  imports: [RouterModule.forRoot(routes, { useHash: true })],//使用hash网址模式

...

})

[Method 2] Modify the following providers in src\app\app.module.ts

@NgModule({

...

  providers: [

    { provide: LocationStrategy, useClass: HashLocationStrategy } // hash模式

    // {provide: LocationStrategy, useClass: PathLocationStrategy} // 无#及h5 history模式

  ],

...

})

Note: Method 2 has a higher priority than method 1. If {provide: LocationStrategy, useClass: PathLocationStrategy} and useHash:true are set at the same time, the hash mode will not take effect; similarly, if { provide: LocationStrategy, useClass: HashLocationStrategy } and useHash: false, the hash mode will take effect instead

 

Extended reading 

How does Vue implement hash mode URLs (that is, the kind of URLs with #, hashtag URLs) #/homehttp://localhost/#/home Extended reading → How Angular implements hash mode URL https://blog.csdn.net/qq_37860634/article/details/124205685

Guess you like

Origin blog.csdn.net/qq_37860634/article/details/124205199