Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js Routing: match end of url

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 ?

like image 696
noirbizarre Avatar asked Oct 08 '22 10:10

noirbizarre


2 Answers

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

like image 30
noirbizarre Avatar answered Oct 13 '22 12:10

noirbizarre


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.

like image 55
WBlasko Avatar answered Oct 13 '22 11:10

WBlasko