aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/routing/redirect.service.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-03-01 13:57:29 +0100
committerChocobozzz <me@florianbigard.com>2018-03-01 13:57:29 +0100
commit901637bb87f5eb0518fb7ca69d98b53ed918339e (patch)
treea8e8943fef7a109ba269d33029174cbdf4dde6d2 /client/src/app/core/routing/redirect.service.ts
parenta73c582e5b6f5c52427b38aaf55b3afbead24053 (diff)
downloadPeerTube-901637bb87f5eb0518fb7ca69d98b53ed918339e.tar.gz
PeerTube-901637bb87f5eb0518fb7ca69d98b53ed918339e.tar.zst
PeerTube-901637bb87f5eb0518fb7ca69d98b53ed918339e.zip
Add ability to change the homepage
Diffstat (limited to 'client/src/app/core/routing/redirect.service.ts')
-rw-r--r--client/src/app/core/routing/redirect.service.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts
new file mode 100644
index 000000000..a0125e0ae
--- /dev/null
+++ b/client/src/app/core/routing/redirect.service.ts
@@ -0,0 +1,48 @@
1import { Injectable } from '@angular/core'
2import { Router } from '@angular/router'
3import { ServerService } from '../server'
4
5@Injectable()
6export class RedirectService {
7 // Default route could change according to the instance configuration
8 static INIT_DEFAULT_ROUTE = '/videos/trending'
9 static DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE
10
11 constructor (
12 private router: Router,
13 private serverService: ServerService
14 ) {
15 // The config is first loaded from the cache so try to get the default route
16 const config = this.serverService.getConfig()
17 if (config && config.instance && config.instance.defaultClientRoute) {
18 RedirectService.DEFAULT_ROUTE = config.instance.defaultClientRoute
19 }
20
21 this.serverService.configLoaded
22 .subscribe(() => {
23 const defaultRouteConfig = this.serverService.getConfig().instance.defaultClientRoute
24
25 if (defaultRouteConfig) {
26 RedirectService.DEFAULT_ROUTE = defaultRouteConfig
27 }
28 })
29 }
30
31 redirectToHomepage () {
32 console.log('Redirecting to %s...', RedirectService.DEFAULT_ROUTE)
33
34 this.router.navigate([ RedirectService.DEFAULT_ROUTE ])
35 .catch(() => {
36 console.error(
37 'Cannot navigate to %s, resetting default route to %s.',
38 RedirectService.DEFAULT_ROUTE,
39 RedirectService.INIT_DEFAULT_ROUTE
40 )
41
42 RedirectService.DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE
43 return this.router.navigate([ RedirectService.DEFAULT_ROUTE ])
44 })
45
46 }
47
48}