Add shorter URLs for accounts and channels client-side
This commit is contained in:
parent
9a911038d9
commit
ff8c5ccf09
|
@ -0,0 +1,41 @@
|
|||
import { Component, OnInit } from '@angular/core'
|
||||
import { empty } from 'rxjs'
|
||||
import { catchError } from 'rxjs/operators'
|
||||
import { RestExtractor } from '@app/core'
|
||||
|
||||
import { ActivatedRoute, Router } from '@angular/router'
|
||||
import { AccountService } from '@app/shared/shared-main/account'
|
||||
|
||||
@Component({
|
||||
selector: 'my-actor',
|
||||
template: ''
|
||||
})
|
||||
export class ActorsComponent implements OnInit {
|
||||
constructor (
|
||||
private accountService: AccountService,
|
||||
private route: ActivatedRoute,
|
||||
private restExtractor: RestExtractor,
|
||||
private router: Router
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit () {
|
||||
const accountOrChannelName = this.route.snapshot.params['actorName'].replace('@', '')
|
||||
|
||||
this.accountService
|
||||
.getAccount(accountOrChannelName)
|
||||
.pipe(
|
||||
catchError(res => {
|
||||
if (res.status === 404 && res.message === 'Account not found') {
|
||||
this.router.navigateByUrl(`/video-channels/${accountOrChannelName}`)
|
||||
return empty()
|
||||
}
|
||||
|
||||
return this.restExtractor.handleError(res)
|
||||
})
|
||||
)
|
||||
.subscribe(() => {
|
||||
this.router.navigateByUrl(`/accounts/${accountOrChannelName}`)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import { MenuGuards } from '@app/core/routing/menu-guard.service'
|
|||
import { POSSIBLE_LOCALES } from '@shared/core-utils/i18n'
|
||||
import { PreloadSelectedModulesList } from './core'
|
||||
import { EmptyComponent } from './empty.component'
|
||||
import { ActorsComponent } from './+actors/actors.component'
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
|
@ -65,6 +66,18 @@ const routes: Routes = [
|
|||
path: 'video-playlists/watch',
|
||||
redirectTo: 'videos/watch/playlist'
|
||||
},
|
||||
{
|
||||
path: 'a',
|
||||
redirectTo: 'accounts'
|
||||
},
|
||||
{
|
||||
path: 'c',
|
||||
redirectTo: 'video-channels'
|
||||
},
|
||||
{
|
||||
path: ':actorName',
|
||||
component: ActorsComponent
|
||||
},
|
||||
{
|
||||
path: '',
|
||||
component: EmptyComponent // Avoid 404, app component will redirect dynamically
|
||||
|
|
Loading…
Reference in New Issue