Ember.js 在 App.Route 中指定位置=“历史记录”的 URL 类型时出错
Ember.js Error in specifying URL type of location='history' in App.Route
我已经开始学习 ember.js 框架,但我被困在如何使用框架具有的 URL 类型功能的设置上。
http://emberjs.com/guides/routing/specifying-the-location-api/
我有这个简单的应用程序.js
App = Ember.Application.create();
App.Router.reopen({
location: 'history'
});
App.Router.map(function () {
this.route('about');
});
App.ApplicationRoute = Ember.Route.extend({
model: function () {
return appdata;
}
});
App.IndexRoute = Ember.Route.extend({
setupController: function (controller) {
// Set the IndexController's `title`
controller.set('indextitle', "My Index title");
},
renderTemplate: function () {
this.render({ outlet: 'indexoutlet' });
}
});
App.AboutRoute = Ember.Route.extend({
model: function () {
return appdata;
},
renderTemplate: function () {
this.render({ outlet: 'aboutoutlet' });
}
});
var appdata = { mytext: '', theplaceholder: 'Enter new text', attr:'Yeap!' }
如果我不使用
App.Router.reopen({
location: 'history'
});
该应用程序工作正常,它通过附加 URL "~/EmberjsTest.aspx#/about"来进入"关于"路由。
但是,因为我不喜欢页面 URL 中的哈希符号,所以我宁愿将其删除,并且指南说我们应该放置以下代码:
App.Router.reopen({
location: 'history'
});
但是当我这样做时,我在Chrome控制台中出现一个错误,说:"断言失败:URL '/EmberjsTest.aspx' 确实匹配了应用程序中的任何路由"
我做错了什么?
提前致谢
如果你想使用历史API,那么你有两个选择。
-
从
'/'
提供您的 Ember 应用程序,以便 Ember 可以使用其"正常"索引/根路由。 -
在 Ember 应用程序中创建一个可以处理
'/EmberjsTest.aspx'
的路由。this.route("index", { path: "/EmberjsTest.aspx" });
请注意,如果您使用选项 2,则可能需要更新所有路由以在其path
中包含'/EmberjsTest.aspx'
。
this.resource("posts", {path: "/EmberjsTest.aspx/posts" })
相关文章:
- window.location替换并传递URL历史记录条目中的变量
- Javascript历史记录转换为php行
- 浏览器何时记录历史记录
- 输入类型按钮返回历史记录并返回顶部
- HTML5历史记录-返回上一个完整页面按钮
- Angular JS-如何强制浏览器记录历史以便快速路由
- asp.net网站文件下载历史记录
- 使用Ajax的后退按钮历史记录,URL中没有散列
- 历史记录和通过JavaScript修改的HTML
- Javascript:历史记录未加载页面
- 通过js设置页面历史记录和页面内容
- 如果没有历史记录,我如何隐藏图像或按钮onclick=;历史.go(-1);
- 将HTML表单发布到iframe会导致浏览器历史记录出现问题
- 如何防止浏览器在历史记录中缓存HTML
- 如何将新的stateObject添加或附加到历史记录中
- 检查浏览器后退按钮历史记录
- React-router 在添加历史记录后不会渲染组件
- 如何返回可用的历史记录状态数
- 引导选项卡不适用于历史记录.返回选项
- js在历史上记录的表单值