forked from hazza/dspace-angular
Merge pull request #2630 from alexandrevryghem/fix-routes-not-relative-to-basehref_contribute-main
Fix handle redirect not working with custom nameSpace
This commit is contained in:
@@ -11,6 +11,8 @@ import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils
|
||||
import { Item } from '../shared/item.model';
|
||||
import { EMBED_SEPARATOR } from './base/base-data.service';
|
||||
import { HardRedirectService } from '../services/hard-redirect.service';
|
||||
import { environment } from '../../../environments/environment.test';
|
||||
import { AppConfig } from '../../../config/app-config.interface';
|
||||
|
||||
describe('DsoRedirectService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
@@ -56,6 +58,7 @@ describe('DsoRedirectService', () => {
|
||||
});
|
||||
|
||||
service = new DsoRedirectService(
|
||||
environment as AppConfig,
|
||||
requestService,
|
||||
rdbService,
|
||||
objectCache,
|
||||
@@ -107,7 +110,7 @@ describe('DsoRedirectService', () => {
|
||||
redir.subscribe();
|
||||
scheduler.schedule(() => redir);
|
||||
scheduler.flush();
|
||||
expect(redirectService.redirect).toHaveBeenCalledWith('/items/' + remoteData.payload.uuid, 301);
|
||||
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/items/${remoteData.payload.uuid}`, 301);
|
||||
});
|
||||
it('should navigate to entities route with the corresponding entity type', () => {
|
||||
remoteData.payload.type = 'item';
|
||||
@@ -124,7 +127,7 @@ describe('DsoRedirectService', () => {
|
||||
redir.subscribe();
|
||||
scheduler.schedule(() => redir);
|
||||
scheduler.flush();
|
||||
expect(redirectService.redirect).toHaveBeenCalledWith('/entities/publication/' + remoteData.payload.uuid, 301);
|
||||
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/entities/publication/${remoteData.payload.uuid}`, 301);
|
||||
});
|
||||
|
||||
it('should navigate to collections route', () => {
|
||||
@@ -133,7 +136,7 @@ describe('DsoRedirectService', () => {
|
||||
redir.subscribe();
|
||||
scheduler.schedule(() => redir);
|
||||
scheduler.flush();
|
||||
expect(redirectService.redirect).toHaveBeenCalledWith('/collections/' + remoteData.payload.uuid, 301);
|
||||
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/collections/${remoteData.payload.uuid}`, 301);
|
||||
});
|
||||
|
||||
it('should navigate to communities route', () => {
|
||||
@@ -142,7 +145,7 @@ describe('DsoRedirectService', () => {
|
||||
redir.subscribe();
|
||||
scheduler.schedule(() => redir);
|
||||
scheduler.flush();
|
||||
expect(redirectService.redirect).toHaveBeenCalledWith('/communities/' + remoteData.payload.uuid, 301);
|
||||
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/communities/${remoteData.payload.uuid}`, 301);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
/* eslint-disable max-classes-per-file */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable, Inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { hasValue } from '../../shared/empty.util';
|
||||
@@ -21,6 +21,7 @@ import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { IdentifiableDataService } from './base/identifiable-data.service';
|
||||
import { getDSORoute } from '../../app-routing-paths';
|
||||
import { HardRedirectService } from '../services/hard-redirect.service';
|
||||
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
|
||||
|
||||
const ID_ENDPOINT = 'pid';
|
||||
const UUID_ENDPOINT = 'dso';
|
||||
@@ -70,6 +71,7 @@ export class DsoRedirectService {
|
||||
private dataService: DsoByIdOrUUIDDataService;
|
||||
|
||||
constructor(
|
||||
@Inject(APP_CONFIG) protected appConfig: AppConfig,
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
@@ -98,7 +100,7 @@ export class DsoRedirectService {
|
||||
let newRoute = getDSORoute(dso);
|
||||
if (hasValue(newRoute)) {
|
||||
// Use a "301 Moved Permanently" redirect for SEO purposes
|
||||
this.hardRedirectService.redirect(newRoute, 301);
|
||||
this.hardRedirectService.redirect(this.appConfig.ui.nameSpace.replace(/\/$/, '') + newRoute, 301);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user