change routing

This commit is contained in:
Przemysław Stawujak 2018-12-13 18:23:52 +01:00
parent c6f0c3059b
commit d519712c2d
3 changed files with 19 additions and 5 deletions

View File

@ -25,7 +25,7 @@ import { CompetitionDetailComponent } from '@app/competition-detail/competition-
{ path: 'about', component: AboutComponent }, { path: 'about', component: AboutComponent },
{ path: 'categories-list', component: CategoriesListComponent, canActivate: [AppRouteGuard] }, { path: 'categories-list', component: CategoriesListComponent, canActivate: [AppRouteGuard] },
{ path: 'categories-list/:id', component: CompetitionsListComponent, canActivate: [AppRouteGuard] }, { path: 'categories-list/:id', component: CompetitionsListComponent, canActivate: [AppRouteGuard] },
{ path: 'categories-list/:id/:competitionId', component: CompetitionDetailComponent, canActivate: [AppRouteGuard] } { path: 'competitions/:id', component: CompetitionDetailComponent, canActivate: [AppRouteGuard] }
] ]
} }
]) ])

View File

@ -1,6 +1,8 @@
import { Component, OnInit, Injector, OnDestroy } from '@angular/core'; import { Component, OnInit, Injector, OnDestroy } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition'; import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/app-component-base'; import { AppComponentBase } from '@shared/app-component-base';
import { Subscription } from 'rxjs/Rx';
import { ActivatedRoute } from '@angular/router';
@Component({ @Component({
templateUrl: './competition-detail.component.html', templateUrl: './competition-detail.component.html',
@ -9,18 +11,29 @@ import { AppComponentBase } from '@shared/app-component-base';
}) })
export class CompetitionDetailComponent extends AppComponentBase implements OnInit, OnDestroy { export class CompetitionDetailComponent extends AppComponentBase implements OnInit, OnDestroy {
private paramSubscription: Subscription;
public competitionId: number;
constructor( constructor(
injector: Injector, injector: Injector,
private route: ActivatedRoute,
) { ) {
super(injector); super(injector);
} }
public ngOnInit() { public ngOnInit() {
this.paramSubscription = this.route.params
.subscribe(params => {
this.competitionId = +params['id'];
console.log('competitionId: ' + this.competitionId)
});
} }
public ngOnDestroy() { public ngOnDestroy() {
if (this.paramSubscription) {
this.paramSubscription.unsubscribe();
}
} }
} }

View File

@ -58,8 +58,9 @@ export class CompetitionsListComponent extends AppComponentBase implements OnIni
} }
public goToDetail(competition: CompetitionDto): void { public goToDetail(competition: CompetitionDto): void {
console.log(this.router.url); //console.log(this.router.url);
const route: string = this.router.url + `/${competition.id}`; //const route: string = this.router.url + `/${competition.id}`;
const route: string = `app/competitions/${competition.id}`;
this.router.navigate([route]); this.router.navigate([route]);
} }