Ember.js Routing: match end of url

2019-05-02 18:26发布

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 ?

2条回答
小情绪 Triste *
2楼-- · 2019-05-02 18:30

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

查看更多
在下西门庆
3楼-- · 2019-05-02 18:45

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.

查看更多
登录 后发表回答