Angular HashLocationStrategy包括目录名

Angular HashLocationStrategy包括目录名,angular,Angular,角度版本9.0 web应用程序部署在目录中 /642f57951edd412f9da095801e657cc6/ APP.module.ts中的APP_BASE HREF设置为/642f57951edd412f9da095801e657cc6/ 现在在路由中添加设置,启用了HashLocationStrategy import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/rou

角度版本9.0

web应用程序部署在目录中
/642f57951edd412f9da095801e657cc6/

APP.module.ts中的
APP_BASE HREF
设置为
/642f57951edd412f9da095801e657cc6/

现在在路由中添加
设置
,启用了
HashLocationStrategy

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { SettingsComponent } from './settings/settings.component';

const routes: Routes =  [
  { path: 'settings', component: SettingsComponent },
];

@NgModule({
  imports: [RouterModule.forRoot(routes, {useHash: true})],
  exports: [RouterModule]
})
export class AppRoutingModule { }
除了出现在web浏览器地址栏中的URL是

当前
http://127.0.0.1:4200/642f57951edd412f9da095801e657cc6/#/642f57951edd412f9da095801e657cc6/settings

通缉
http://127.0.0.1:4200/642f57951edd412f9da095801e657cc6/#/settings


有没有一种方法可以让它如上所示,但仍然托管在
/642f57951edd412f9da095801e657cc6/
文件夹中?

在URL中看到的任何内容都是正确的,它实际上会以这种方式工作

URL的格式为

https(or)https://domainName/BaseRef/#/your routing paths
如果您希望URL像

https(or)https://domainName/#/your routing paths
生成时将basehref指定为“/”,将deployURl指定为“642f57951edd412f9da095801e657cc6”或文件夹名:示例

ng build --prod --output-path docs --base-href / --deploy-url /642f57951edd412f9da095801e657cc6/
您的基本URL将是
/
,这意味着您的URL看起来像
http://127.0.0.1:4200/#/settings


这意味着index.html将位于主文件夹中,您应该将脚本放置在构建时指定的文件夹名称中(参数为--deploy url)

在托管您之后,您会遇到这种情况。我没有说清楚,我想用
/642f57951edd412f9da095801e657cc6/
保留基本url,但是我想要角度的显示
http://127.0.0.1:4200/642f57951edd412f9da095801e657cc6/#/settings
非常简单,然后将base href设为/642f57951edd412f9da095801e657cc6/,将部署url设为/642f57951edd412f9da095801e657cc6/,并将所有javascript生成的文件移动到该文件夹,将index.html放在folderHi@Ravi之外,部署路径也是“/642f57951edd412f9da095801e657cc6/”。。简而言之,这些文件部署在目录中。但是url哈希路径中显示的url不包括文件夹。Hi@Mr.wangfromnexto或者我可以知道
642f57951edd412f9da095801e657cc6
folderHi@Ravi,
https://domainname/642f57951edd412f9da095801e657cc6/index.html
。我想让URL在地址中显示为:
https://domainname/642f57951edd412f9da095801e657cc6/#/home
而不是
https://domainname/642f57951edd412f9da095801e657cc6/#/642f57951edd412f9da095801e657cc6/home
ng build --prod --output-path docs --base-href / --deploy-url /642f57951edd412f9da095801e657cc6/