简体   繁体   English

Express的角路由

[英]Angular Routing with Express

Right now I have a simple Angular project set up with Express serving my index.html file. 现在,我有一个简单的Angular项目,使用Express为我的index.html文件设置。 Later on in the project, I realized I needed a landing page that needs some of the functionality (form input that makes an API call) of index.html file. 在项目的稍后部分,我意识到我需要一个登陆页面,该登陆页面需要index.html文件的某些功能(进行API调用的表单输入)。 How would I go about Express taking care of my routes? Express Express如何照顾我的路线? Do I need to change it so my landing page is served from express? 我是否需要更改它以便从Express投放我的目标网页? Also, if the above is true, would it be good practice to rename the landing page to 'index.html' and have the main page renamed to something else? 另外,如果上述情况是正确的,将登陆页面重命名为“ index.html”并将主页重命名为其他内容是一种好习惯吗?

While you can split your site up however you want, the point of angular really is for building single page applications. 虽然您可以根据需要拆分站点,但角度的确是构建单页应用程序。 This means that usually you would combine your landing page with the rest of your site into a single angular project. 这意味着通常您会将着陆页与网站的其余部分合并为一个角度项目。 Then you would handle your routing inside angular. 然后,您将在angular内处理路由。 For example: 例如:

yourdomain.com/#/landing - landing page
yourdomain.com/#/home - some other part of your site

By doing this, you end up just serving your entire project from index.html like you are currently doing, and you also don't have to duplicate any of your project code. 这样一来,您最终就可以像目前一样从index.html服务整个项目,并且您也不必重复任何项目代码。


If you are familiar with angular routing, that's great, but if not, I prefer ui-router over the standard routing library: https://github.com/angular-ui/ui-router 如果您熟悉角度路由,那很好,但是如果不熟悉,我更喜欢ui-router而不是标准路由库: https : //github.com/angular-ui/ui-router

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

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