AngularJS路由VS后端路由 [英] AngularJS routing vs backend routing

查看:225
本文介绍了AngularJS路由VS后端路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的下一个项目使用AngularJS。
与Python的后端和HTML5,角前端的应用。

I would like to use AngularJS in my next project. The application with Python backend and html5, Angular frontend.

我要在后端使用MVC框架,我有点困惑。
我一定要使用对后端布线,也前台?

I am going to use MVC framework on backend and I am little bit confused. Do I have to use routing on backend and also frontend?

由于我总是用后端路由,并在前端路由确实是新的想法对我来说。

Because I always used backend routing and routing on frontend is really new idea for me.

时客户端路由的更好吗?当我选择使用前端路由,会有对后端没有路线?所有的请求将被发送给一个网址?

Is client side routing better? And when I choose to use frontend routing, there will be no routes on backend? All request will be send to one url?

推荐答案

您可以使用客户端的路由,让后端返回静态文件和JSON数据。
在角路由基本上告诉你,你需要从服务器上下载这部分的模板和控制器处理程序的。

You can use client-side routing and let the backend return static files and JSON data. The routing in Angular basically tell you which partial template you need to download from server and which controller will handler it.

您后端的路线会是这样

'/partials/:name' -> return corresponding partial

'/api/*' -> handlers to return json data

'/*' -> return index.html

您的index.html将包含参考其他意见

Your index.html will contain reference to other views

...
<div ng-view></div>
...

现在让说你去yourapp.com/someview.html~~V。服务器返回
index.html,然后从该URL / someview,角会询问someview从服务器部分,并相应地呈现页面。

Now let say you go to yourapp.com/someview.html. The server returns index.html and since the url is /someview, Angular will ask for "someview" partial from server and render the page accordingly.

总之,服务器角色是index.html的回报,谐音和服务REST API请求。客户总是收到index.html,然后根据网址,请求coressponding泛音和JSON数据。

In short, the server role is to return index.html, partials and serve REST API request. The client always receive index.html and based on the url, request for coressponding partials and JSON data.

这篇关于AngularJS路由VS后端路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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