本文介绍了AngularJs路由,服务器多次请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用angularjs路由,我使用,但它使得服务器端额外的请求。任何人都知道这个问题的解决方案,或者说我做错了什么?
客户端app.js
的app.config(['$ routeProvider','$ locationProvider',函数($ routeProvider,$ locationProvider){ $ locationProvider.html5Mode({启用:真,requireBase:假}) $ routeProvider。 什么时候('/', { templateUrl:/tpl/main.tmp.html', 控制器:'MainCtrl }) 不然的话({redirectTo:'/'})}])//routes.jsapp.get('/',函数(REQ,RES){ 的console.log(测试) res.render(__目录名称+'/公/ TPL / index.html的,siteConfig)})//输出//测试//测试//测试//测试文件:
模型上市| -css| -js| --app.js| --angular.jsapp.js解决方案
有几件事情可能会导致此,无论是请求报文进一步的检查可能缩小的原因。一些想法检查:
- 浏览器会试图获取该网站favicon因为它无法找到一个
- 抓取的图像在网址一个#(即< IMG SRC =#/> )
- 元刷新标记在HTML
- 当rel=\"nofollow\">连接
I want to use angularjs routing, I'm using but it's making extra requests in server side. Anyone know the solution of this problem, or I'm doing something wrong?
Client app.js
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) { $locationProvider.html5Mode({enabled: true, requireBase: false}) $routeProvider. when('/', { templateUrl: '/tpl/main.tmp.html', controller: 'MainCtrl' }) .otherwise({redirectTo: '/'}) }]) //routes.js app.get('/', function(req, res) { console.log("test") res.render(__dirname+'/public/tpl/index.html', siteConfig) }) //output //test //test //test //testFiles:
models public |-css |-js |--app.js |--angular.js app.js解决方案
A few things may cause this, a closer inspection of both request packets might narrow down the cause. Some ideas to check for:
- The browser keeps trying to fetch the site favicon because it can't find one
- Fetching an image with a # in the URL (i.e. <img src="#"/>)
- Meta refresh tag in the HTML
- Web browsers may retry requests when the connection is closed before receiving a response
更多推荐
AngularJs路由,服务器多次请求
发布评论