【发布时间】:2019-04-24 00:19:09
【问题描述】:
我构建 Angular 项目。将 dist 文件夹粘贴到 src/main/resources/static 中,现在我可以从控制器调用 index.html 文件。但问题是 (localhost:4200/homePage?empId=1234) 是起始页面无法从控制器调用此页面。 代码如下(弹簧控制器)
@RequestMapping("/homePage")
public String testMethod() {
return "/index.html";
}
而index.html是这样的
<!doctype html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>TestApp</title>
<base href="/homePage">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--link rel="icon" type="image/x-icon" href="favicon.ico"-->
<link rel="stylesheet"
href="http://localhost:8080/homePage/styles.2e25b77c70b5269b3e1c.css">
</head>
<body>
<app-root></app-root>
<script type="text/javascript"
src="http://localhost:8080/homePage/runtime.ec2944dd8b20ec099bf3.js">
</script>
<script type="text/javascript"
src="http://localhost:8080/homePage/polyfills.b58e3c18bf0ef2973262.js">
</script>
<script type="text/javascript"
src="http://localhost:8080/homePage/main.b4ad8245c5085d925098.js">
</script>
</body>
</html
想要访问此页面 (localhost:4200/homePage?empId=1234)。
【问题讨论】:
-
您通过提供 dist 文件夹正在做正确的事情。只需在角度侧实现哈希路由。因此,任何类似于 : (localhost:4200/#/homePage?empId=1234 的东西都将从角度侧调用,而 URl 之类的 : (localhost:4200/homePage?empId=1234) 将被调用用于 API
-
const routes: Routes = [ {path :'personCreate', component: PersonCreateComponent}, {path: 'personSearch', component: PersonSearchComponent}, {path: 'PersonUpdate', component: PersonUpdateComponent}, {路径:'serchTransfer',组件:SearchTransferComponent},{路径:'transferRequest/:personID',组件:TransferRequestComponent},{路径:'homePage',组件:HomePageComponent}]; @NgModule({ 进口:[RouterModule.forRoot(routes)],出口:[RouterModule] })
-
我已经有角码路由
-
您没有启用 hashRouting。修改如下: [RouterModule.forRoot(routes,{useHash: true })]
标签: javascript java spring angular