mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 18:44:14 +00:00
75940: Item page redirects
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
|
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { RemoteData } from '../core/data/remote-data';
|
import { RemoteData } from '../core/data/remote-data';
|
||||||
import { ItemDataService } from '../core/data/item-data.service';
|
import { ItemDataService } from '../core/data/item-data.service';
|
||||||
@@ -7,13 +7,17 @@ import { Item } from '../core/shared/item.model';
|
|||||||
import { followLink } from '../shared/utils/follow-link-config.model';
|
import { followLink } from '../shared/utils/follow-link-config.model';
|
||||||
import { FindListOptions } from '../core/data/request.models';
|
import { FindListOptions } from '../core/data/request.models';
|
||||||
import { getFirstCompletedRemoteData } from '../core/shared/operators';
|
import { getFirstCompletedRemoteData } from '../core/shared/operators';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
import { hasValue } from '../shared/empty.util';
|
||||||
|
import { getItemPageRoute } from './item-page-routing-paths';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a resolver that requests a specific item before the route is activated
|
* This class represents a resolver that requests a specific item before the route is activated
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ItemPageResolver implements Resolve<RemoteData<Item>> {
|
export class ItemPageResolver implements Resolve<RemoteData<Item>> {
|
||||||
constructor(private itemService: ItemDataService) {
|
constructor(private itemService: ItemDataService,
|
||||||
|
private router: Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +37,18 @@ export class ItemPageResolver implements Resolve<RemoteData<Item>> {
|
|||||||
followLink('version', undefined, true, true, true, followLink('versionhistory')),
|
followLink('version', undefined, true, true, true, followLink('versionhistory')),
|
||||||
).pipe(
|
).pipe(
|
||||||
getFirstCompletedRemoteData(),
|
getFirstCompletedRemoteData(),
|
||||||
|
map((rd: RemoteData<Item>) => {
|
||||||
|
if (rd.hasSucceeded && hasValue(rd.payload)) {
|
||||||
|
const itemRoute = getItemPageRoute(rd.payload);
|
||||||
|
const thisRoute = state.url;
|
||||||
|
if (!thisRoute.startsWith(itemRoute)) {
|
||||||
|
const itemId = rd.payload.uuid;
|
||||||
|
const subRoute = thisRoute.substring(thisRoute.indexOf(itemId) + itemId.length, thisRoute.length);
|
||||||
|
this.router.navigateByUrl(itemRoute + subRoute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rd;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user