问题
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 matchroot.repo.files.index/myrepo/files/READMEwill matchroot.repo.files.subwithpath=README/myrepo/files/folder/READMEwill matchroot.repo.files.suband will reroute me to/myrepo/files/folder/becausepath=folderinstead ofpath=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