我是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(应用程序的入口点)。