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

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

问题描述

我正在使用Ember.js的功能来构建一个包含文件管理器的应用程序。我想以... /#/ files / Nested / Inside /的形式嵌套文件夹的URL,并且可以使用 linkTo ;但是,如果我刷新(或直接访问URL),我有错误消息没有路由匹配URL/ files / Nested / Inside。有没有办法使Ember.js在这样的情况下工作?谢谢。



这是我目前的路线设置:

  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
},
序列化:function(folder){
return {path:folder.get('path')}
}
$)


解决方案

哇,有趣的问题。它应该可能,但我没有尝试过,或者看到野外的任何例子。



在引擎盖下,ember使用发音符号路由器路由识别器来解析路由。该路线的自述说明了如何定义更复杂的路线,如:

  router.map(function(match){
//这将匹配任何东西,后跟斜杠
//之后是一个动态段(一个或多个非
//斜杠字符)
match(/ * page /:location)。to(showPage);
});

所以要使嵌套文件夹工作,你可能会这样做:

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

希望这有帮助。


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.

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' })
})

Hope this helps.

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

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