Skip to content

Commit 59c439a

Browse files
author
Jake Goldsborough
committed
adding auto redirect to repo when hitting crates /repo url
1 parent 0288ef9 commit 59c439a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Router.map(function() {
2222

2323
// Well-known routes
2424
this.route('docs');
25+
this.route('repo');
2526
});
2627
this.route('me', function() {
2728
this.route('crates');

app/routes/crate/repo.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Ember from 'ember';
2+
3+
export default Ember.Route.extend({
4+
redirect() {
5+
var crate = this.modelFor('crate');
6+
7+
var repository = crate.get('repository');
8+
if (repository) {
9+
window.location = repository;
10+
} else {
11+
// Redirect to the crate's main page and show a flash error if
12+
// no repository is found
13+
var message = 'Crate does not supply a repository URL';
14+
this.controllerFor('application').set('nextFlashError', message);
15+
this.replaceWith('crate', crate);
16+
}
17+
},
18+
});

0 commit comments

Comments
 (0)