如何在角度7

时间:2019-04-17 11:02:28

标签: angular url hash angular7

我是我项目中angular 7的新手,我想删除URL中的#(hash)

这是我实际的url https://dev.abc.com/web/

但是当我访问此url时,它会像这样https://dev.abc.com/web/#/添加#(hash)

这是我的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中的#(哈希)

1 个答案:

答案 0 :(得分:0)

它的PathLocationStrategy是Angular中的默认位置策略。

检查模块导入,也可以通过提供{useHash:true}作为add_action( 'send_entry_list_notification', array( $this, 'trigger' ), 10, 2 ); 的第二个参数来覆盖它:

var json = [
  [{
      "apiName": "Name",
      "value": "Bob"
    },
    {
      "apiName": "CompanyName",
      "value": "Google"
    }
  ],
  [{
      "apiName": "Name",
      "value": "Micky"
    },
    {
      "apiName": "CompanyName",
      "value": "Amazon"
    }
  ],
  [{
      "apiName": "Name",
      "value": "Donal"
    },
    {
      "apiName": "CompanyName",
      "value": "Facebook"
    }
  ]
];

function findValueByProperty(item, propertyName) {
  var relevantRow = item.find(function(content) {
    return content.apiName === propertyName;
  });
  return relevantRow.value;
}

function comparator(propertyName) {
  return function(a, b) {
    var valueA = findValueByProperty(a, propertyName);
    var valueB = findValueByProperty(b, propertyName);
    return valueA.localeCompare(valueB)
  }
}

console.log('json==>' + JSON.stringify(json));
console.log(json.slice().sort(comparator("CompanyName")));
console.log(json.slice().sort(comparator("Name")));

还请注意,在使用PathLocationStrategy时,您需要配置Web服务器以为所有请求的位置提供index.html(应用程序的入口点)。