在Django提供的Angular 2应用程序中,如何在重新加载页面时使Angular 2 URL与Django一起使用?
In Angular 2 app that's served by Django, how to make the Angular 2 URL work with Django when reloading the page?
具体来说,假设Django服务的页面的网址为localhost:8000/home.该页面包含3个标签,其中一个是Angular应用.单击该选项卡将显示Angular应用程序,并且URL更改为localhost:8000/home/ng_app.现在,如果使用 this url 刷新浏览器,则Django将显示404,这是有道理的,因为Django应用程序中不存在localhost:8000/home/ng_app.
Specifically, say a page served by Django has the url localhost:8000/home. The page contains 3 tabs and under one of which is an Angular app. Clicking on that tab shows the Angular app, and the url changes to localhost:8000/home/ng_app. Now if the browser is refreshed with this url, Django will show a 404, which makes sense because localhost:8000/home/ng_app is not present in the Django app.
那么如何使Angular URL工作呢? (输入localhost:8000/home/ng_app会导致Angular应用而不是404).谢谢!
So how to make the Angular URL work? (entering localhost:8000/home/ng_app leads to the Angular app instead of 404). Thanks!
推荐答案您应该考虑在角度应用中将哈希爆炸用作URL.结帐本教程是通过谷歌搜索发现的,该URL也使用了刘海.
You should consider using hash bangs in your angular app as URLs. Checkout this tutorial I found by googling which also uses has bangs for URLs.
通过这种方式,角度应用程序URL不会与您的Django应用程序冲突,并且Angular会出于路由目的将其选中
In this way the angular app URLs wont conflict with your Django app and Angular would pick it up for routing purposes
更多推荐
如何使Django与Angular URL兼容
发布评论