簡體   English   中英

如何在 angular 7 的 URL 中刪除 Hash(#)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM