Ember.js 嵌套文件夹,如路由(包含斜线) [英] Ember.js Nested folder like route (contain slash)

查看:21
本文介绍了Ember.js 嵌套文件夹,如路由(包含斜线)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Ember.js 构建一个具有文件管理器功能的应用程序.我想要 ".../#/files/Nested/Inside/" 形式的嵌套文件夹的 URL,它与 linkTo 一起工作正常;但是,如果我刷新(或直接转到 URL),我会收到错误消息没有路由匹配 URL '/files/Nested/Inside'".有没有办法让 Ember.js 在这种情况下工作?谢谢.

I'm building an app with file manager like functionality with Ember.js. I'd like the URL for nested folder in the form of ".../#/files/Nested/Inside/" and it works fine with linkTo; however if I refresh (or go to the URL directly) I have the error message "No route match the URL '/files/Nested/Inside'". Is there any way to make Ember.js works in situation like this? Thanks.

这是我当前的路线设置:

Here is my current route setup:

FM.Router.map(function() {
  this.resource('folders', { path: '/files' })
  this.resource('folder', { path: '/files/:path' })
})

FM.FoldersRoute = EM.Route.extend({
  model: function() {
    return FM.Folder.find('/')
  }
})

FM.FolderRoute = EM.Route.extend({
  model: function(params) {
    return ns.Folder.find(params.path)
  },
  serialize: function(folder) {
    return { path: folder.get('path') }
  }
})

推荐答案

哇,有趣的问题.它应该是可能的,但我自己没有尝试过,也没有在野外看到任何这样的例子.

Wow, interesting question. It should be possible but I've not tried it myself or seen any examples of this in the wild.

在底层,ember 使用 tildeio routerroute-recognizer 来解析路由.该路线的自述文件解释了如何定义更详细的路线,例如:

Under the hood, ember uses the tildeio router and route-recognizer to resolve routes. The route's readme explains how to define more elaborate routes like:

router.map(function(match) {
  // this will match anything, followed by a slash,
  // followed by a dynamic segment (one or more non-
  // slash characters)
  match("/*page/:location").to("showPage");
});

因此,要使嵌套文件夹正常工作,您可以执行以下操作:

So to get nested folders working, you might be able to do something like this:

FM.Router.map(function() {
  this.resource('folders', { path: '/files' })
  this.resource('folder', { path: '/files/*path' })
})

希望这会有所帮助.

这篇关于Ember.js 嵌套文件夹,如路由(包含斜线)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆