【问题标题】:Get current route name from corresponding loading route in ember从 ember 中对应的加载路径获取当前路径名称
【发布时间】:2021-02-16 03:10:45
【问题描述】:

根据 ember document 如果路由中的任何模型挂钩需要时间从服务器获取数据,ember 将插入 loading 路由。例如test-loading,此时如果我们尝试获取当前路由名称,如this,它只返回加载路由。例如,如果sample 路由加载时间过长,ember 将转换为sample-loading,直到sample 路由解决。然后它将再次更改为sample 路由。所以在样本加载时getCurrentRoute 返回sample-loading。在我的情况下,我需要知道实际的路由名称,它变成了-loading。我在互联网上找不到任何这样做的文档。如果有人知道实施的方式或想法,请与我分享..

【问题讨论】:

  • 你能从路由名称字符串的末尾删除-loading 吗?可能我理解错了

标签: ember.js ember-data ember-router


【解决方案1】:

务实的做法如下:

let currentRoute = 'sample-loading';

if (currentRoute.endsWith('-loading')) {
  currentRoute = currentRoute.substring(0, currentRoute.lastIndexOf("-loading"));
}

console.log(currentRoute);

【讨论】:

    猜你喜欢
    • 2023-01-11
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 2013-08-20
    • 1970-01-01
    • 2016-06-05
    • 1970-01-01
    • 2015-02-01
    相关资源
    最近更新 更多