AngularJs路由,服务器多次请求

编程入门 行业动态 更新时间:2024-10-20 13:50:07
本文介绍了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 //test

Files:

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路由,服务器多次请求

本文发布于:2023-10-12 17:04:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485332.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   服务器   AngularJs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!