Arj*_*jun 6 angular-routing angular
我正在Angular 2中开发一个Web应用程序,它在我的本地主机上可以正常工作,但是当我在生产环境中托管时,它的不起作用我的子域被替换为空字符串
我的生产服务器是 http:// foobar:8888 / Hrms
其中“ Hrms”是我托管“发布文件”的子域
当我在本地运行时,URL为:http:// localhost:50739 /#/ access / login ,在服务器中,子域自动丢失:http:// foobar:8888 /#/
我尝试HTTP:// foobar的:8888 / HRMS /#/门禁/登录,但它仍然会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 { }
Run Code Online (Sandbox Code Playgroud)
请让我知道,我什么时候做错了谢谢。
您必须更改文件tag中的基础index.html:
<base href="/">到<base href="/hrms">
角度路由器使用此标签来了解每条路线的基础在哪里,这就是为什么它在开发中工作但在生产中不起作用的原因。
| 归档时间: |
|
| 查看次数: |
5492 次 |
| 最近记录: |