Skip to content

Commit 952e8ba

Browse files
committed
Extract the redirection logic to a new service
The service can be used from other routes that modify window.location.
1 parent fac7766 commit 952e8ba

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

app/routes/install.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,9 @@ import Route from '@ember/routing/route';
22
import { inject as service } from '@ember/service';
33

44
export default Route.extend({
5-
fastboot: service(),
5+
redirector: service(),
66

77
redirect() {
8-
this._redirectTo('https://doc.rust-lang.org/cargo/getting-started/installation.html');
9-
},
10-
11-
_redirectTo(url) {
12-
if (this.fastboot.isFastBoot) {
13-
let headers = this.fastboot.response.headers;
14-
headers.set('location', url);
15-
this.set('fastboot.response.statusCode', 301);
16-
} else {
17-
window.location = url;
18-
}
8+
this.redirector.redirectTo('https://doc.rust-lang.org/cargo/getting-started/installation.html');
199
},
2010
});

app/services/redirector.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Service, { inject as service } from '@ember/service';
2+
3+
export default Service.extend({
4+
fastboot: service(),
5+
6+
redirectTo(url) {
7+
if (this.fastboot.isFastBoot) {
8+
let headers = this.fastboot.response.headers;
9+
headers.set('location', url);
10+
this.set('fastboot.response.statusCode', 301);
11+
} else {
12+
window.location = url;
13+
}
14+
},
15+
});

0 commit comments

Comments
 (0)