代码之家  ›  专栏  ›  技术社区  ›  Ashwini Verma

如何在Angular7中设置静态文件的基本路径?

  •  0
  • Ashwini Verma  · 技术社区  · 7 年前

    第一次:索引.html

    <base href="/customer">
    

    第二:应用程序模块.ts

    @NgModule({
      providers: [{provide: APP_BASE_HREF, useValue: '/customer'}]
    })
    

    第三:应用程序-路由.module.ts

    const routes: Routes = [
      { path: "", redirectTo: "/customer", pathMatch: "full" },
      {
        path: "customer",
        component: CustomerComponent,
        data: { animation: "HomePage" }
      }
    ];
    

    上面所有的方法都很适合URL路由,我得到了想要的URL。

    http://localhost:4200/customer

    http://localhost:4200/ '. 我需要它 http://localhost:4200/customer/main.js

    因此,我正在努力做到 http://localhost:4200/客户/main.js 而不是 http://localhost:4200/main.js 出于某种安全验证的原因。

    enter image description here

    0 回复  |  直到 7 年前
        1
  •  4
  •   Avin Kavish    7 年前

    你可以使用 --baseHref ng serve ng build 这意味着您不再需要为中的路由添加前缀 app-routing.module.ts

    ng serve --baseHref=/customer/
    

    使用

    ng build --baseHref=/customer/
    
        2
  •  0
  •   Alexia    6 年前

    <base href="/"> 进入索引.html但是脚本仍然从相对路径加载,这可能是因为没有 <body> <车身>

    推荐文章