From 3bfc1ba6bb5d2e848af4e500f30fb9a1595f5c85 Mon Sep 17 00:00:00 2001 From: Arunmozhi Date: Tue, 9 Apr 2024 17:16:35 +1000 Subject: [PATCH] fix: use full path in the enrollment failure urls The enrollment failure URLs were using the React Router's location.pathname, which omits the basename when the MFE is deployed in a sub-directory. This commit instead uses the global.location.pathname (browser location api) to make sure that the full path including the sub-directory is used. --- src/components/course/data/hooks.jsx | 4 ++-- src/components/course/data/utils.jsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/course/data/hooks.jsx b/src/components/course/data/hooks.jsx index f00d095f64..0da152e01f 100644 --- a/src/components/course/data/hooks.jsx +++ b/src/components/course/data/hooks.jsx @@ -299,9 +299,9 @@ export const useCourseEnrollmentUrl = ({ () => ({ next: `${config.LMS_BASE_URL}/courses/${courseRunKey}/course`, // Redirect back to the same page with a failure query param - failure_url: `${global.location.origin}${location.pathname}?${baseQueryParams.toString()}`, + failure_url: `${global.location.origin}${global.location.pathname}?${baseQueryParams.toString()}`, }), - [config.LMS_BASE_URL, courseRunKey, baseQueryParams, location.pathname], + [config.LMS_BASE_URL, courseRunKey, baseQueryParams], ); const enrollmentUrl = useMemo( diff --git a/src/components/course/data/utils.jsx b/src/components/course/data/utils.jsx index e95797200e..cfdfd5a1df 100644 --- a/src/components/course/data/utils.jsx +++ b/src/components/course/data/utils.jsx @@ -793,7 +793,7 @@ export const createEnrollFailureUrl = ({ courseRunKey, location }) => { baseQueryParams.set(ENROLLMENT_FAILED_QUERY_PARAM, true); baseQueryParams.set(ENROLLMENT_COURSE_RUN_KEY_QUERY_PARAM, courseRunKey); - return `${global.location.origin}${location.pathname}?${baseQueryParams.toString()}`; + return `${global.location.origin}${global.location.pathname}?${baseQueryParams.toString()}`; }; export const createEnrollWithLicenseUrl = ({