如何使Django与Angular URL兼容 [英] how to make Django play well with Angular URL

查看:92
本文介绍了如何使Django与Angular URL兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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服务的页面的网址为http://localhost:8000/home.该页面包含3个标签,其中一个是Angular应用.单击该选项卡将显示Angular应用程序,并且URL更改为http://localhost:8000/home/ng_app.现在,如果使用 this url 刷新浏览器,则Django将显示404,这是有道理的,因为Django应用程序中不存在http://localhost:8000/home/ng_app.

Specifically, say a page served by Django has the url http://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 http://localhost:8000/home/ng_app. Now if the browser is refreshed with this url, Django will show a 404, which makes sense because http://localhost:8000/home/ng_app is not present in the Django app.

那么如何使Angular URL工作呢? (输入http://localhost:8000/home/ng_app会导致Angular应用而不是404).谢谢!

So how to make the Angular URL work? (entering http://localhost:8000/home/ng_app leads to the Angular app instead of 404). Thanks!

推荐答案

您应该考虑在角度应用中将哈希爆炸用作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兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆