我正在Angular 2中开发一个Web应用程序,它在我的localhost中工作正常,但是当我在生产环境中托管时它无法工作 我的子域名正在替换为空字符串
我的生产服务器是 的 http://foobar:8888/Hrms
其中" Hrms"是我托管我的"发布文件"
的子域当我在本地运行时,网址为: http://localhost:50739/#/access/login 并且在服务器中子域自动丢失: http://foobar:8888/#/
我尝试了 http://foobar:8888/hrms/#/access/login ,但仍然会自动 http://foobar:8888/#/
代码
var domainName = "";
if (location.hostname !== "localhost")
domainName = "HRMS/";
const appRoutes: Routes = [
{
path: "access", component: AccessComponent,
children: [
{ path: "", redirectTo: "login", pathMatch: "full" },
{ path: domainName + "login", component: LoginComponent, data: { title: "Login" }, canActivate: [UserGuard] },
{ path: domainName + "forgot-password", component: ForgotPasswordComponent, data: { title: "Forgot Password" }, canActivate: [UserGuard] },
{ path: domainName + "not-found", component: PageNotFoundComponent, data: { title: "Page Not Found" } },
{ path: domainName + "lock-me/:path", component: LockComponent, data: { title: "Locked" }, canActivate: [LockGuard] }
]
},
{
path: "app", component: LayoutComponent,
canActivate: [AuthGuard],
children: [
{ path: "", redirectTo: "getting-started", pathMatch: "full" },
{ path: domainName + "dashboard", component: DashboardComponent, data: { title: "Dashboard" } },
{ path: domainName + "getting-started", component: GettingStartedComponent, data: { title: "Getting Started" } },
{ path: domainName + "accounts", component: AccountsComponent, data: { title: "Accounts" } },
{ path: domainName + "organization", component: OrganizationComponent, data: { title: "Organization" } },
{ path: domainName + "interviews", component: InterviewsComponent, data: { title: "Interviews" } }
]
},
{ path: "", redirectTo: domainName + "access/login", pathMatch: "full" },
{ path: "**", redirectTo: domainName + "access/not-found", pathMatch: "full" }
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes, { useHash: true })
],
exports: [
RouterModule
]
})
export class AppRouting { }
请告诉我,我什么时候做错了 感谢。
答案 0 :(得分:3)
您必须更改tag
文件中的基础index.html
:
<base href="/">
至<base href="/hrms">
这个标记被有角度的路由器用来知道每条路由的基础在哪里,这就是为什么它在开发中工作时不能在生产中工作的原因。
答案 1 :(得分:1)
正如@supamiu所说,问题很可能是基础href。但是,在对index.html中的路径进行硬编码时,在对生产工件进行gerating时,请使用flag --base-href your_app_prefix。这样最终的索引文件将包含正确的基本href和app应该按预期工作。
答案 2 :(得分:0)
构建时,请按如下方式使用--base-href属性:
res = []
tmp = df.set_index('Student_Name').T
for col in list(tmp):
res.append(tmp[col].nlargest(3)[tmp[col].nlargest(3) > 80].index.tolist())
res = [x if len(x) > 0 else np.NaN for x in res]
df['Top_3_above_80'] = res