From 74ce163bece35903f6d2959eceb31a1fb7c20188 Mon Sep 17 00:00:00 2001 From: Eugene Dyudyunov Date: Thu, 29 Feb 2024 14:59:46 +0200 Subject: [PATCH] fix: correct internal routes The Content dropdown items have incorrect URLs for the internal routing when MFEs are deployed using the common domain and the PUBLIC_PATH. Introduce the new function to check the path correctness ( it already exists in master) and wrap the navigational links with it. --- src/utils.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index 67a37e6db..a66601288 100644 --- a/src/utils.js +++ b/src/utils.js @@ -95,12 +95,31 @@ export function parseArrayOrObjectValues(obj) { return result; } +/** + * Create a correct inner path depend on config PUBLIC_PATH. + * @param {string} checkPath - the internal route path that is validated + * @returns {string} - the correct internal route path + */ +export const createCorrectInternalRoute = (checkPath) => { + let basePath = getConfig().PUBLIC_PATH; + + if (basePath.endsWith('/')) { + basePath = basePath.slice(0, -1); + } + + if (!checkPath.startsWith(basePath)) { + return `${basePath}${checkPath}`; + } + + return checkPath; +}; + export function getPagePath(courseId, isMfePageEnabled, urlParameter) { if (isMfePageEnabled === 'true') { if (urlParameter === 'tabs') { - return `${getConfig().BASE_URL}/course/${courseId}/pages-and-resources`; + return createCorrectInternalRoute(`/course/${courseId}/pages-and-resources`); } - return `${getConfig().BASE_URL}/course/${courseId}/${urlParameter}`; + return createCorrectInternalRoute(`/course/${courseId}/${urlParameter}`); } return `${getConfig().STUDIO_BASE_URL}/${urlParameter}/${courseId}`; }