ember.js - 使用 HistoryLocation 从不匹配的路线转移用户

标签 ember.js

随着 1.5.1 中 HistoryLocation 的新实现,rootURL 参数现在需要尾部斜杠。这现在会导致用户在没有尾部斜杠的情况下尝试访问应用程序,因为 ember 认为它找不到路由。

例如,我的应用程序位于 /path/to/app,这是现有用户已收藏的内容,默认情况下从我们的服务器端框架链接(它在应用程序 url 中创建带有修剪后的斜杠).

有没有办法,

1.在 HistoryLocation rootURL 中不允许有尾部斜线 2. 在尝试访问没有尾部斜杠的应用程序时转换使用路由器的用户?

在我的服务器上,我有一个 window.rootURL,其中包含没有尾部斜线的应用程序根 URL(有基于访问资源的动态段)。 在我的路由器中,我有以下内容:

App.Router.reopen({
    location: 'auto',
    rootURL: window.rootURL + '/'
});

我可以运行类似的东西

if (location.pathName == window.rootURL) {
    window.location.assign(window.rootURL + '/');
}

但这会强制重新加载页面,这似乎不需要重新加载,因为我已经有一个完整的 Ember 应用程序正在运行。

Since this application shares components with a few Ember applications we have in our code base and there are dynamic segments in the rootURL, creating routes just to redirect wouldn't make much sense (at least IMO).

那么,这个问题的最佳解决方案是什么?

最佳答案

无需多想,您可以使用 replaceState,它不会重新加载页面,但会更新 url 以访问您的 ember 应用。

window.history.replaceState({},"", pathWithSlash);

关于ember.js - 使用 HistoryLocation 从不匹配的路线转移用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23394073/

相关文章:

bdd - 如何在 Emberjs 上对 View 绑定(bind)和模板进行单元测试?

namespaces - Ember.js 模型中的保留属性名称

javascript - Ember 依赖项 "Uncaught TypeError: $(...).fitText is not a function"

ember.js - 仅当从 didInsertElement 调用 get ('controller' )时,从 View 观察 Controller 属性才有效

javascript - Ember.TextField 值绑定(bind)到父 View

javascript - 如何将动态段传递给 ember 组件

javascript - Ember 和外部 js 脚本

javascript - Ember.Select 中的绑定(bind)操作

ember.js - 如何将路由传递到组件内的#link-to

javascript - Ember-CLI 与 Laravel 或其他后端框架一起使用