diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-11 15:27:46 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-11 15:27:46 +0100 |
commit | dae5ca24b173aebd16de2a202ccd4088568b8dfb (patch) | |
tree | 29d07d765478776b7c3f91f40443be1acb561df9 /client/src/app/core/routing/redirect.service.ts | |
parent | f481c4f9f31e897a08e818f388fecdee07f57142 (diff) | |
download | PeerTube-dae5ca24b173aebd16de2a202ccd4088568b8dfb.tar.gz PeerTube-dae5ca24b173aebd16de2a202ccd4088568b8dfb.tar.zst PeerTube-dae5ca24b173aebd16de2a202ccd4088568b8dfb.zip |
Redirect to the last url on login
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) { |