diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
commit | 88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch) | |
tree | b242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /client/src/app/core/routing/redirect.service.ts | |
parent | 53a94c7cfa8368da4cd248d65df8346905938f0c (diff) | |
parent | 9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff) | |
download | PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip |
Merge branch 'develop' into pr/1217
Diffstat (limited to 'client/src/app/core/routing/redirect.service.ts')
-rw-r--r-- | client/src/app/core/routing/redirect.service.ts | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts index 1881be117..e1db4097b 100644 --- a/client/src/app/core/routing/redirect.service.ts +++ b/client/src/app/core/routing/redirect.service.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { Router } from '@angular/router' | 2 | import { NavigationEnd, Router } from '@angular/router' |
3 | import { ServerService } from '../server' | 3 | import { ServerService } from '../server' |
4 | 4 | ||
5 | @Injectable() | 5 | @Injectable() |
@@ -8,6 +8,9 @@ export class RedirectService { | |||
8 | static INIT_DEFAULT_ROUTE = '/videos/trending' | 8 | static INIT_DEFAULT_ROUTE = '/videos/trending' |
9 | static DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE | 9 | static DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE |
10 | 10 | ||
11 | private previousUrl: string | ||
12 | private currentUrl: string | ||
13 | |||
11 | constructor ( | 14 | constructor ( |
12 | private router: Router, | 15 | private router: Router, |
13 | private serverService: ServerService | 16 | private serverService: ServerService |
@@ -18,6 +21,7 @@ export class RedirectService { | |||
18 | RedirectService.DEFAULT_ROUTE = config.instance.defaultClientRoute | 21 | RedirectService.DEFAULT_ROUTE = config.instance.defaultClientRoute |
19 | } | 22 | } |
20 | 23 | ||
24 | // Load default route | ||
21 | this.serverService.configLoaded | 25 | this.serverService.configLoaded |
22 | .subscribe(() => { | 26 | .subscribe(() => { |
23 | const defaultRouteConfig = this.serverService.getConfig().instance.defaultClientRoute | 27 | const defaultRouteConfig = this.serverService.getConfig().instance.defaultClientRoute |
@@ -26,6 +30,21 @@ export class RedirectService { | |||
26 | RedirectService.DEFAULT_ROUTE = defaultRouteConfig | 30 | RedirectService.DEFAULT_ROUTE = defaultRouteConfig |
27 | } | 31 | } |
28 | }) | 32 | }) |
33 | |||
34 | // Track previous url | ||
35 | this.currentUrl = this.router.url | ||
36 | router.events.subscribe(event => { | ||
37 | if (event instanceof NavigationEnd) { | ||
38 | this.previousUrl = this.currentUrl | ||
39 | this.currentUrl = event.url | ||
40 | } | ||
41 | }) | ||
42 | } | ||
43 | |||
44 | redirectToPreviousRoute () { | ||
45 | if (this.previousUrl) return this.router.navigateByUrl(this.previousUrl) | ||
46 | |||
47 | return this.redirectToHomepage() | ||
29 | } | 48 | } |
30 | 49 | ||
31 | redirectToHomepage (skipLocationChange = false) { | 50 | redirectToHomepage (skipLocationChange = false) { |