Ember CLI,locationType:‘hash’,并为所有 URL 服务 index.html
Ember CLI, locationType: ‘hash’, and serving index.html for all URLs
我有一个特定的用例,我想使用 URL 散列在 Ember 内进行路由,并且我希望 URL 的路径部分有点动态也是。
例如:
localhost:4200/#/properties/edit
工作方式与此完全相同:
localhost:4200/about/#/properties/edit
或者这样:
localhost:4200/products/widgets/model-5000/#/properties/edit
如果在上面的这些不同示例 URL 之间导航会产生完整的页面刷新,那将是 100% 可以接受的,尽管 URL 中的任何哈希更改都会将其保留在 "single page."
我希望所有这些 URL 指向 app/index.html
文件,并且 Ember CLI 指向 "ignore" 路径,但我想不通了解如何配置 Ember CLI 在为应用程序提供服务时执行此操作。例如,上面的 /about
场景给我错误 Cannot GET /about
.
使用普通 Ember CLI 是否可行,或者我是否需要转向 ember-cli-rails
之类的东西才能在开发中获得更灵活的路由?我假设配置它以在生产中正常工作会相对简单,但我也需要一些适用于开发的东西。
是的,您可以使用通配符:http://emberjs.com/guides/routing/defining-your-routes/#toc_wildcard-globbing-routes
从 'ember' 导入 Ember;
从 './config/environment';
导入配置
var 路由器 = Ember.Router.extend({
位置:config.locationType
});
Router.map(function() {
this.resource('index', { path: "/*wildcard" }, function() {
this.route("properties", function() {
this.route("edit");
});
});
});
export default Router;
解决方案是创建一个 Ember CLI 附加组件:ember-cli-hash-anywhere。
安装后,Web 服务器会忽略 URL 的路径部分,每次都提供 index.html
。
我有一个特定的用例,我想使用 URL 散列在 Ember 内进行路由,并且我希望 URL 的路径部分有点动态也是。
例如:
localhost:4200/#/properties/edit
工作方式与此完全相同:
localhost:4200/about/#/properties/edit
或者这样:
localhost:4200/products/widgets/model-5000/#/properties/edit
如果在上面的这些不同示例 URL 之间导航会产生完整的页面刷新,那将是 100% 可以接受的,尽管 URL 中的任何哈希更改都会将其保留在 "single page."
我希望所有这些 URL 指向 app/index.html
文件,并且 Ember CLI 指向 "ignore" 路径,但我想不通了解如何配置 Ember CLI 在为应用程序提供服务时执行此操作。例如,上面的 /about
场景给我错误 Cannot GET /about
.
使用普通 Ember CLI 是否可行,或者我是否需要转向 ember-cli-rails
之类的东西才能在开发中获得更灵活的路由?我假设配置它以在生产中正常工作会相对简单,但我也需要一些适用于开发的东西。
是的,您可以使用通配符:http://emberjs.com/guides/routing/defining-your-routes/#toc_wildcard-globbing-routes
从 'ember' 导入 Ember; 从 './config/environment';
导入配置var 路由器 = Ember.Router.extend({ 位置:config.locationType });
Router.map(function() {
this.resource('index', { path: "/*wildcard" }, function() {
this.route("properties", function() {
this.route("edit");
});
});
});
export default Router;
解决方案是创建一个 Ember CLI 附加组件:ember-cli-hash-anywhere。
安装后,Web 服务器会忽略 URL 的路径部分,每次都提供 index.html
。