Javascript 使用pyramid和ember.js路由温泉
我正在使用pyramid提供的ember.js开发一个SPA(单页应用程序)。问题是路由没有正常工作 在金字塔中,我定义了以下路线:Javascript 使用pyramid和ember.js路由温泉,javascript,python,ember.js,url-routing,pyramid,Javascript,Python,Ember.js,Url Routing,Pyramid,我正在使用pyramid提供的ember.js开发一个SPA(单页应用程序)。问题是路由没有正常工作 在金字塔中,我定义了以下路线: # Route to index.html, i.e. the SPA config.add_route('index', '/') # Route to css & js resources config.add_static_view('', 'myapp:static') 而索引视图是: @view_config(route_name='index
# Route to index.html, i.e. the SPA
config.add_route('index', '/')
# Route to css & js resources
config.add_static_view('', 'myapp:static')
而索引
视图是:
@view_config(route_name='index')
def index_view(request):
with open('myapp/templates/index.html', 'rt', encoding='utf-8') as fh:
html = fh.read()
return Response(html, content_type='text/html')
这是我的index.html
:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="libs/bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<h1>Hello, world!</h1>
<script type="text/x-handlebars" data-template-name="wfw">
<section id="wfw">
<p>here is a page</p>
</section>
</script>
<script src="js/application.js"></script>
<script src="js/router.js"></script>
<script src="https://code.jquery.com/jquery.js"></script>
<script src="http://builds.emberjs.com/release/ember.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
<script src="https://raw.github.com/less/less.js/master/dist/less-1.6.0.min.js"></script>
<script src="libs/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
js/router.js
:
window.Wfw = Ember.Application.create();
Wfw.Router.map(function () {
this.resource('wfw', { path: '/t' });
});
当我转到localhost:6543/
时,我会看到“你好,世界!”,但我没有看到“这是一个页面”。如果我将js/router.js
中的路径更改为'/test'
并转到localhost:6543/test
,我会得到一个404。我做错了什么?我是否需要以某种方式禁用金字塔的部分路由,或者我是否对ember做了一些错误的事情?以下几点:
我认为您需要将Ember.js脚本标记移到特定于应用程序的标记之上
您配置的路径是/t
,因此我认为它不会选择/test
默认情况下,ember不使用html5历史api,因此您的url需要类似于:localhost:6543/#/t
谢谢/t
只是问题中的一个输入错误,但问题出在缺少的#
上。当我补充说它工作得非常好!