我设法通过以下步骤解决了此问题,例如http:// localhost:8080 / angular / player / detail /
4:
1)使用以下命令构建角度应用程序:ng build –prod -bh ./ -d / angular
2)将已构建应用的内容复制到$ ApacheLocation / webapps / angular
3)重写规则:
RewriteCond %{REQUEST_PATH} !-fRewriteRule ^/angular/(.*) /angular?path=$14)在app.component.ts上的设置导航:
constructor(private activatedRoute: ActivatedRoute, private router: Router) { }ngonInit() {const path = this.activatedRoute.snapshot.queryParams['path'];const navigateTo = '/' + path;if (path) { this.router.navigate([navigateTo]);}}
您可以在这里找到测试项目:https :
//github.com/avuletica/test
重写规则说明:
# %{REQUEST_PATH} corresponds to the full path that is used for mapping.# ! NOT character # '-f' (is regular file) Treats the TestString as a pathname and tests whether or not it exists, and is a regular file.# ^ matches the beginning of the string or line# . matches any charceter except line breaks# * match 0 or more of the preceding token因此,基本上,如果在/ angular/anything上没有文件,tomcat会将完整路径作为查询字符串发送到angular应用程序,并且从该查询参数angular处理路由。



