我正在开发flask+Angular+MongoDb应用程序。我正在使用angular中的状态提供程序。状态从应用程序加载得非常好。但是当我刷新页面时,它抛出404错误。在
application = Flask(__name__) @application.route('/') def showMachineList(): print ("Inside the show machine list function") return application.make_response(open('templates/index.html').read())
angular.module('testapp', ['ngCookies', 'ngResource', 'ngSanitize', 'ui.router', 'ui.bootstrap','ngMaterial','ngCookies' ]) .config(function($urlRouterProvider, $locationProvider,$interpolateProvider) { $urlRouterProvider.otherwise('/'); //$interpolateProvider.startSymbol('//').endSymbol('//'); $locationProvider.html5Mode(true).hashPrefix('!'); });
angular.module('testapp') .config(function ($stateProvider) { console.log("inside create outage request") $stateProvider .state('cor', { url: '/cor', template: '<cor></cor>' //templateUrl: '/static/client/app/acn/acn.html' }); });
我在中添加了<base href="/">
索引.html也。
当我用"http://localhost:5000/cor"
刷新页面时,它抛出404。
你能告诉我我缺少什么吗?在
刷新页面时,浏览器会将URL“http://localhost:5000/cor”发送到服务器。正如我在代码中看到的,没有定义
/cor
路由,只有/
。我想你必须定义一个。在问题可能出在您的模板中:您在其中定义了指向
^{pr2}$cor
的链接。你应该有这样的东西:我假设你写的是:
这是单页应用程序中相当常见的问题。看起来Angular应用程序可以在客户端正确地处理
cor
状态,但是web服务器无法知道在初始加载时,/cor
路径应该路由到相同的Angular应用程序。在尝试向终结点添加第二条路由:
或者,可以使用catch-all route来处理任何路径后缀。在
相关问题 更多 >
编程相关推荐