Ember.js Routing: match end of url

為{幸葍}努か 提交于 2019-12-07 05:36:22

问题


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

With this router:

  • /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

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


回答1:


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.

Basic Usage

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

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.




回答2:


There is an opened issue on Ember.js Github Tracker: https://github.com/emberjs/ember.js/issues/1451



来源:https://stackoverflow.com/questions/11151423/ember-js-routing-match-end-of-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!