File tree 4 files changed +23
-3
lines changed
4 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -3,13 +3,14 @@ import { inject as service } from '@ember/service';
3
3
4
4
export default Route . extend ( {
5
5
flashMessages : service ( ) ,
6
+ redirector : service ( ) ,
6
7
7
8
redirect ( ) {
8
9
let crate = this . modelFor ( 'crate' ) ;
9
10
10
11
let documentation = crate . get ( 'documentation' ) ;
11
12
if ( documentation ) {
12
- window . location = documentation ;
13
+ this . redirector . redirectTo ( documentation ) ;
13
14
} else {
14
15
// Redirect to the crate's main page and show a flash error if
15
16
// no documentation is found
Original file line number Diff line number Diff line change @@ -3,13 +3,14 @@ import { inject as service } from '@ember/service';
3
3
4
4
export default Route . extend ( {
5
5
flashMessages : service ( ) ,
6
+ redirector : service ( ) ,
6
7
7
8
redirect ( ) {
8
9
let crate = this . modelFor ( 'crate' ) ;
9
10
10
11
let repository = crate . get ( 'repository' ) ;
11
12
if ( repository ) {
12
- window . location = repository ;
13
+ this . redirector . redirectTo ( repository ) ;
13
14
} else {
14
15
// Redirect to the crate's main page and show a flash error if
15
16
// no repository is found
Original file line number Diff line number Diff line change 1
1
import Route from '@ember/routing/route' ;
2
+ import { inject as service } from '@ember/service' ;
2
3
3
4
export default Route . extend ( {
5
+ redirector : service ( ) ,
6
+
4
7
redirect ( ) {
5
- window . location = 'https://doc.rust-lang.org/cargo/getting-started/installation.html' ;
8
+ this . redirector . redirectTo ( 'https://doc.rust-lang.org/cargo/getting-started/installation.html' ) ;
6
9
} ,
7
10
} ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments