简体   繁体   English

不同HTML页面上的Angular2应用

[英]Angular2 app on a different HTML page

I'm working on an Angular2 app and have a requirement to not bootstrap the application on index.html. 我正在使用Angular2应用,并且有一个要求不要在index.html上引导应用程序。 Given that NG2 uses the HTML5 routing features, this doesn't work too well if you are not using index.html as your bootstrap. 鉴于NG2使用了HTML5路由功能,因此如果您未将index.html用作引导程序,则此方法将不能很好地工作。 (Especially if you refresh the page) (尤其是刷新页面时)

  1. What is the preferred way to bootstrap an NG2 application, not on index.html? 引导NG2应用程序而不是在index.html上的首选方式是什么?

  2. How do you preserve the url/routing so that a page refresh works? 如何保存url /路由,以便页面刷新有效? (again, not on index.html) (同样,不在index.html上)

you can totally serve Angular on any HTML page, Route persistence depends on your server technology. 您可以在任何HTML页面上完全提供Angular,路由持久性取决于您的服务器技术。

If you are using angular-cli, you can configure index file in .angular-cli.json file 如果您正在使用angular-cli,则可以在.angular-cli.json文件中配置索引文件

"index": "myhomepage.html"

Whenever a route is called it goes to server to look up the Files, If your Server is configured to correctly Route they can be persisted. 每当调用路由时,都会去服务器查找文件。如果服务器配置为正确路由,则可以将其保留。

Hope this helps!! 希望这可以帮助!!

您可以在应用程序根模块中使用APP_BASE_HREF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM