diff --git a/app/router.js b/app/router.js index ee35611828b..077daa46f82 100644 --- a/app/router.js +++ b/app/router.js @@ -22,6 +22,7 @@ Router.map(function() { // Well-known routes this.route('docs'); + this.route('repo'); }); this.route('me', function() { this.route('crates'); diff --git a/app/routes/crate/repo.js b/app/routes/crate/repo.js new file mode 100644 index 00000000000..6983c71f34d --- /dev/null +++ b/app/routes/crate/repo.js @@ -0,0 +1,18 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + redirect() { + var crate = this.modelFor('crate'); + + var repository = crate.get('repository'); + if (repository) { + window.location = repository; + } else { + // Redirect to the crate's main page and show a flash error if + // no repository is found + var message = 'Crate does not supply a repository URL'; + this.controllerFor('application').set('nextFlashError', message); + this.replaceWith('crate', crate); + } + }, +});