angularjs漂亮的URL不起作用

编程入门 行业动态 更新时间:2024-10-21 22:58:37
本文介绍了angularjs漂亮的URL不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的问题是,没有#,URL无法正常工作.这是我的代码:

My problem is url is not working without # . Here is my code :

angular.module('Hiren', ['ngRoute']) .config(function ($routeProvider, $locationProvider) { $routeProvider .when('/', { templateUrl: 'partials/login.html', controller: 'login' }) .when('/redirect', { templateUrl: 'partials/postLogin.html', controller: 'postLogin' }); $locationProvider.html5Mode(true); });

当我尝试浏览网址example/redirect时,它显示404,但是使用哈希(example/#redirect)可以正常工作.

When I try to browse the url example/redirect , it gives me 404 , but using hash ( example/#redirect) its perfectly working .

推荐答案

如果您在HTML5模式下获取404,则需要配置服务器以在以下情况下为Angular应用程序提供服务(通常为index.html或app.html): 404发生在服务器上.您没有提及服务器使用的内容,因此我无法提供具体说明.这比Angular问题更多的是服务器配置问题.

If you're getting a 404 in HTML5 mode you need to configure your server to serve your Angular application (usually index.html or app.html) when a 404 happens on the server. You don't mention what you're using for a server so I can't give specific instructions on how to do that. This is more a server configuration issue than an Angular one.

立即编辑该服务器的已知名称:

Edit now that server is known:

import SimpleHTTPServer, SocketServer import urlparse, os PORT = 3000 class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): # Parse query data to find out what was requested parsedParams = urlparse.urlparse(self.path) # See if the file requested exists if os.access('.' + os.sep + parsedParams.path, os.R_OK): # File exists, serve it up SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self); else: # redirect to index.html self.send_response(302) self.send_header('Content-Type', 'text/html') self.send_header('location', '/index.html') self.end_headers() Handler = MyHandler httpd = SocketServer.TCPServer(("", PORT), Handler) print "serving at port", PORT httpd.serve_forever()

参考的SO答案.

更多推荐

angularjs漂亮的URL不起作用

本文发布于:2023-10-31 16:23:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546622.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   漂亮   angularjs   URL

发布评论

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

>www.elefans.com

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