diff --git a/app/routes/crate/docs.js b/app/routes/crate/docs.js index 2579eb95e9e..f978d12210a 100644 --- a/app/routes/crate/docs.js +++ b/app/routes/crate/docs.js @@ -3,13 +3,14 @@ import { inject as service } from '@ember/service'; export default Route.extend({ flashMessages: service(), + redirector: service(), redirect() { let crate = this.modelFor('crate'); let documentation = crate.get('documentation'); if (documentation) { - window.location = documentation; + this.redirector.redirectTo(documentation); } else { // Redirect to the crate's main page and show a flash error if // no documentation is found diff --git a/app/routes/crate/repo.js b/app/routes/crate/repo.js index 8ff337aadf5..97cbc5fa3e3 100644 --- a/app/routes/crate/repo.js +++ b/app/routes/crate/repo.js @@ -3,13 +3,14 @@ import { inject as service } from '@ember/service'; export default Route.extend({ flashMessages: service(), + redirector: service(), redirect() { let crate = this.modelFor('crate'); let repository = crate.get('repository'); if (repository) { - window.location = repository; + this.redirector.redirectTo(repository); } else { // Redirect to the crate's main page and show a flash error if // no repository is found diff --git a/app/routes/install.js b/app/routes/install.js index 7c52f9ce3da..972a971285b 100644 --- a/app/routes/install.js +++ b/app/routes/install.js @@ -1,7 +1,10 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; export default Route.extend({ + redirector: service(), + redirect() { - window.location = 'https://doc.rust-lang.org/cargo/getting-started/installation.html'; + this.redirector.redirectTo('https://doc.rust-lang.org/cargo/getting-started/installation.html'); }, }); diff --git a/app/services/redirector.js b/app/services/redirector.js new file mode 100644 index 00000000000..8a382d2d1cc --- /dev/null +++ b/app/services/redirector.js @@ -0,0 +1,15 @@ +import Service, { inject as service } from '@ember/service'; + +export default Service.extend({ + fastboot: service(), + + redirectTo(url) { + if (this.fastboot.isFastBoot) { + let headers = this.fastboot.response.headers; + headers.set('location', url); + this.set('fastboot.response.statusCode', 301); + } else { + window.location = url; + } + }, +});