[英]How to remove Hash(#) in URL on angular 7
我是項目中angular 7
的新手,我想刪除URL
中的 #(hash)
這是我的實際url
https://dev.abc.com/web/
但是當我訪問這個url
時,它會像這樣添加 #(hash) https://dev.abc.com/web/#/
這是我的routing.module.js
代碼
import { NgModule } from '@angular/core';
import { RouterModule, Routes, Router } from '@angular/router';
import { HomeComponent } from '../views/home/home.component';
import { CubberComponent } from '../views/cubber/cubber.component';
import { SignupComponent } from '../views/cubber/signup/signup.component';
import { SigninComponent } from '../views/cubber/signin/signin.component';
import { MyinformationComponent } from '../views/cubber/myinformation/myinformation.component';
import { ProfileComponent } from '../views/cubber/profile/profile.component';
import { PasswordComponent } from '../views/cubber/password/password.component';
import { MyaddressComponent } from '../views/cubber/myaddress/myaddress.component';
import { AuthGuard } from '../service/auth/auth.guard';
import { DashboardComponent } from '../views/cubber/dashboard/dashboard.component';
import { MylistingComponent } from '../views/cubber/mylisting/mylisting.component';
import { MyavailablityComponent } from '../views/cubber/myavailablity/myavailablity.component';
import { MyphotosComponent } from '../views/cubber/myphotos/myphotos.component';
import { MypaymentComponent } from '../views/cubber/mypayment/mypayment.component';
export const routes: Routes = [
{
path: '',
component: HomeComponent,
pathMatch: 'full'
},
{
path: 'signup',
component: SignupComponent,
data: { title: 'signup' }
}
];
@NgModule({
imports: [
RouterModule.forRoot(routes)],
exports: []
})
export class AppRoutingModule {
constructor(private router: Router) {
this.router.errorHandler = (error: any) => {
this.router.navigate(['login']);
};
}
}
我參考了一些博客,它在@NgModule
中說添加userHash:false
像這樣
@NgModule({
imports: [
RouterModule.forRoot(routes,{userHash:false})],
exports: []
})
我不確定它是否有效。
請幫我刪除
url
中的 #(hash)
它的 PathLocationStrategy 是 Angular 中的默認位置策略。
檢查你的模塊導入,它也可以通過提供 { useHash: true } 作為RouterModule.forRoot
的第二個參數來覆蓋:
imports: [
...
RouterModule.forRoot(routes, { useHash: false })
]
另請注意,在使用 PathLocationStrategy 時,您需要配置您的 Web 服務器,以便為所有請求的位置提供 index.html(應用程序的入口點)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.