Ember.js路由:匹配url的结尾 [英] Ember.js Routing: match end of url

查看:95
本文介绍了Ember.js路由:匹配url的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一个路径与URL匹配。路径必须是给定模式后URL的结尾,但我不能做到。
Ember.js总是结束它与下一个斜线匹配。

I need to match a path into an URL. The path has to be the end of the URL after a given pattern, but I can't do it. Ember.js always end it's matching to the next slash.

var router = Ember.Router.extend({
    location: 'history',
    enableLogging: true,
    root: Ember.Route.extend({
        index: Ember.Route.extend({
            route: '/'

            repo: Ember.Route.extend({
                route: '/:repo_id',

                index: Ember.Route.extend({
                    route: '/'
                }),

                files: Ember.Route.extend({
                    route: '/files',

                    index: Ember.Route.extend({
                        route: '/'
                    }),

                    sub: Ember.Route.extend({
                        route: '/:path'
                    })
                })
            })
        })
    })
});

使用此路由器:


  • / myrepo / files / 将匹配 root.repo.files.index

  • / myrepo / files / README 将匹配 root.repo.files.sub path = README

  • / myrepo / files / folder / README 将匹配 root.repo.files.sub ,并将重新路由到 / myrepo / files / folder / ,因为 path = folder 而不是 path = folder / README

  • /myrepo/files/ will match root.repo.files.index
  • /myrepo/files/README will match root.repo.files.sub with path=README
  • /myrepo/files/folder/README will match root.repo.files.sub and will reroute me to /myrepo/files/folder/ because path=folder instead of path=folder/README

如果子路由与:path 的URL结尾匹配,即使有斜杠也不行?

How can I to have sub route match the end of URL with :path even when there is slash into it or not ?

推荐答案

此功能已承诺到Ember.js存储库的 master 分支。它不在 1.0.0-pre2 构建中,因此,直到新版本发布,您将需要自己构建Ember.js 或查找预建版本。

This functionality has been committed to the Ember.js repository's master branch. It is not in the 1.0.0-pre2 build, so until a new version is released you will need to either build Ember.js yourself or find a prebuilt version.

使用星号 * 为< C $ C>。您的路由将使用类似于以下语法:

Instead of prefixing your dynamic segment with a colon :, use an asterisk *. Your route will use a syntax similar to:

Ember.Route.extend({
  route: '/:repo_id/files/*path'
});

路径段将可用,就像它是一个正常的动态属性一样。但是,它将包含URL中的 files / 之后的任何内容,包括斜杠。

The path segment will be available just as if it were a normal dynamic property. However, it will include anything after files/ in the URL, including slashes.

这篇关于Ember.js路由:匹配url的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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