{
- history.replace(PAGES.HOME_PAGE, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 0 },
+ });
}}
showSchool={true}
showClass={true}
diff --git a/src/teachers-module/pages/DisplayClasses.tsx b/src/teachers-module/pages/DisplayClasses.tsx
index b73e57474a..940243001d 100644
--- a/src/teachers-module/pages/DisplayClasses.tsx
+++ b/src/teachers-module/pages/DisplayClasses.tsx
@@ -8,6 +8,7 @@ import { PAGES, TableTypes } from '../../common/constants';
import BackButton from '../../components/common/BackButton';
import './DisplayClasses.css';
import logger from '../../utility/logger';
+import { parsePath } from 'history';
const DisplayClasses: FC = () => {
const history = useHistory();
@@ -40,10 +41,13 @@ const DisplayClasses: FC = () => {
const schoolCourses = await api.getCoursesBySchoolId(tempSchool.id);
if (schoolCourses.length === 0) {
- history.replace(PAGES.SUBJECTS_PAGE, {
- schoolId: tempSchool.id,
- origin: PAGES.DISPLAY_CLASSES,
- isSelect: true,
+ history.replace({
+ ...parsePath(PAGES.SUBJECTS_PAGE),
+ state: {
+ schoolId: tempSchool.id,
+ origin: PAGES.DISPLAY_CLASSES,
+ isSelect: true,
+ },
});
return;
}
@@ -53,9 +57,12 @@ const DisplayClasses: FC = () => {
user.id,
);
if (fetchedClasses.length === 0) {
- history.replace(PAGES.ADD_CLASS, {
- school: currentSchool,
- origin: PAGES.DISPLAY_CLASSES,
+ history.replace({
+ ...parsePath(PAGES.ADD_CLASS),
+ state: {
+ school: currentSchool,
+ origin: PAGES.DISPLAY_CLASSES,
+ },
});
return;
}
@@ -74,10 +81,13 @@ const DisplayClasses: FC = () => {
);
if (classWithoutSubjects) {
- history.replace(PAGES.SUBJECTS_PAGE, {
- classId: classWithoutSubjects.classId,
- origin: PAGES.DISPLAY_CLASSES,
- isSelect: true,
+ history.replace({
+ ...parsePath(PAGES.SUBJECTS_PAGE),
+ state: {
+ classId: classWithoutSubjects.classId,
+ origin: PAGES.DISPLAY_CLASSES,
+ isSelect: true,
+ },
});
Util.clearNavigationState();
return;
@@ -90,7 +100,7 @@ const DisplayClasses: FC = () => {
const handleClassSelection = (selectedClass: TableTypes<'class'>) => {
Util.setCurrentClass(selectedClass);
- history.replace(PAGES.HOME_PAGE, { tabValue: 0 });
+ history.replace({ ...parsePath(PAGES.HOME_PAGE), state: { tabValue: 0 } });
};
return (
diff --git a/src/teachers-module/pages/DisplaySchools.tsx b/src/teachers-module/pages/DisplaySchools.tsx
index e3a992a196..6867369889 100644
--- a/src/teachers-module/pages/DisplaySchools.tsx
+++ b/src/teachers-module/pages/DisplaySchools.tsx
@@ -27,6 +27,7 @@ import { useAppSelector } from '../../redux/hooks';
import { RootState } from '../../redux/store';
import { AuthState } from '../../redux/slices/auth/authSlice';
import logger from '../../utility/logger';
+import { parsePath } from 'history';
interface SchoolWithRole {
school: TableTypes<'school'>;
@@ -172,15 +173,27 @@ const DisplaySchools: FC = () => {
existingRequest?.request_status === STATUS.REQUESTED ||
existingRequest?.request_status === STATUS.FLAGGED
) {
- history.replace(PAGES.POST_SUCCESS, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.POST_SUCCESS),
+ state: { tabValue: 0 },
+ });
} else if (existingRequest?.request_status === STATUS.REJECTED) {
- history.replace(PAGES.SEARCH_SCHOOL, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.SEARCH_SCHOOL),
+ state: { tabValue: 0 },
+ });
} else if (existingRequest?.request_status === STATUS.APPROVED) {
// If approved but school not in list, go to Search School to avoid flicker/loop
- history.replace(PAGES.SEARCH_SCHOOL, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.SEARCH_SCHOOL),
+ state: { tabValue: 0 },
+ });
} else {
- history.replace(PAGES.SEARCH_SCHOOL, {
- origin: PAGES.DISPLAY_SCHOOLS,
+ history.replace({
+ ...parsePath(PAGES.SEARCH_SCHOOL),
+ state: {
+ origin: PAGES.DISPLAY_SCHOOLS,
+ },
});
}
setLoading(false);
@@ -261,12 +274,18 @@ const DisplaySchools: FC = () => {
localStorage.setItem(USER_SELECTION_STAGE, JSON.stringify(true));
const tempClass = Util.getCurrentClass();
if (tempClass) {
- history.replace(PAGES.HOME_PAGE, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 0 },
+ });
} else {
const classes = await getClasses(school.school.id, currentUser?.id);
if (classes.length > 0) {
Util.setCurrentClass(classes[0]);
- history.replace(PAGES.HOME_PAGE, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 0 },
+ });
}
}
void Util.validateCurrentSchoolContext();
@@ -304,8 +323,11 @@ const DisplaySchools: FC = () => {
- history.replace(PAGES.REQ_ADD_SCHOOL, {
- origin: PAGES.DISPLAY_SCHOOLS,
+ history.replace({
+ ...parsePath(PAGES.REQ_ADD_SCHOOL),
+ state: {
+ origin: PAGES.DISPLAY_SCHOOLS,
+ },
})
}
>
diff --git a/src/teachers-module/pages/EditClass.tsx b/src/teachers-module/pages/EditClass.tsx
index 384d7a8466..076b30f2b5 100644
--- a/src/teachers-module/pages/EditClass.tsx
+++ b/src/teachers-module/pages/EditClass.tsx
@@ -18,6 +18,7 @@ import {
getGradeNameFromStandard,
getStandardFromClassName,
} from '../../utility/classGradeMapper';
+import { parsePath } from 'history';
type LocationState = {
school?: TableTypes<'school'>;
@@ -98,10 +99,13 @@ const EditClass: FC = () => {
);
setIsSaving(false);
Util.setNavigationState(School_Creation_Stages.CLASS_COURSE);
- history.replace(PAGES.SUBJECTS_PAGE, {
- classId: newClass.id,
- origin: PAGES.ADD_CLASS,
- isSelect: true,
+ history.replace({
+ ...parsePath(PAGES.SUBJECTS_PAGE),
+ state: {
+ classId: newClass.id,
+ origin: PAGES.ADD_CLASS,
+ isSelect: true,
+ },
});
}
} catch (error) {
@@ -135,20 +139,25 @@ const EditClass: FC = () => {
if (paramOrigin === PAGES.MANAGE_CLASS) {
Util.setPathToBackButton(PAGES.MANAGE_CLASS, history);
} else if (paramOrigin != PAGES.SUBJECTS_PAGE) {
- history.replace(
- paramOrigin === PAGES.HOME_PAGE
- ? PAGES.HOME_PAGE
- : PAGES.DISPLAY_SCHOOLS,
- paramOrigin === PAGES.HOME_PAGE ? { tabValue: 0 } : null,
- );
+ history.replace({
+ ...parsePath(
+ paramOrigin === PAGES.HOME_PAGE
+ ? PAGES.HOME_PAGE
+ : PAGES.DISPLAY_SCHOOLS,
+ ),
+ state: paramOrigin === PAGES.HOME_PAGE ? { tabValue: 0 } : null,
+ });
return;
} else if (paramOrigin === PAGES.SUBJECTS_PAGE) {
if (!currentSchool) return;
Util.setNavigationState(School_Creation_Stages.SCHOOL_COURSE);
- history.replace(PAGES.SUBJECTS_PAGE, {
- schoolId: currentSchool.id,
- origin: PAGES.DISPLAY_SCHOOLS,
- isSelect: true,
+ history.replace({
+ ...parsePath(PAGES.SUBJECTS_PAGE),
+ state: {
+ schoolId: currentSchool.id,
+ origin: PAGES.DISPLAY_SCHOOLS,
+ isSelect: true,
+ },
});
return;
}
diff --git a/src/teachers-module/pages/EditSchool.tsx b/src/teachers-module/pages/EditSchool.tsx
index 23ab8d9939..bff8d84eac 100644
--- a/src/teachers-module/pages/EditSchool.tsx
+++ b/src/teachers-module/pages/EditSchool.tsx
@@ -12,6 +12,8 @@ import { RoleType } from '../../interface/modelInterfaces';
import { Util } from '../../utility/util';
import ProfileDetails from '../components/library/ProfileDetails';
import logger from '../../utility/logger';
+import { parsePath } from 'history';
+
interface LocationState {
school?: SchoolWithRole['school'];
role?: RoleType;
@@ -134,17 +136,19 @@ const EditSchool: React.FC = () => {
};
const onBackButtonClick = () => {
- history.replace(
- prevOrigin === PAGES.DISPLAY_SCHOOLS
- ? PAGES.DISPLAY_SCHOOLS
- : isEditMode && !navigationState
- ? PAGES.SCHOOL_PROFILE
- : PAGES.MANAGE_SCHOOL,
- {
+ history.replace({
+ ...parsePath(
+ prevOrigin === PAGES.DISPLAY_SCHOOLS
+ ? PAGES.DISPLAY_SCHOOLS
+ : isEditMode && !navigationState
+ ? PAGES.SCHOOL_PROFILE
+ : PAGES.MANAGE_SCHOOL,
+ ),
+ state: {
school: school,
role: role,
},
- );
+ });
};
const [profilePic, setProfilePic] = useState(null);
diff --git a/src/teachers-module/pages/HomePage.tsx b/src/teachers-module/pages/HomePage.tsx
index 1f30a481f3..b473971364 100644
--- a/src/teachers-module/pages/HomePage.tsx
+++ b/src/teachers-module/pages/HomePage.tsx
@@ -43,6 +43,7 @@ import Library from '../components/library/Library';
import ReportTable from '../components/reports/ReportsTable';
import './HomePage.css';
import { format, subDays } from 'date-fns';
+import { parsePath } from 'history';
const HomePage: React.FC = () => {
const history = useHistory();
@@ -274,7 +275,7 @@ const HomePage: React.FC = () => {
const handleLibraryBack = () => {
setShowAssignOptionsScreen(true);
setTabValue(2);
- history.replace(PAGES.HOME_PAGE, { tabValue: 2 });
+ history.replace({ ...parsePath(PAGES.HOME_PAGE), state: { tabValue: 2 } });
};
const isLibraryTab = tabValue === 1;
const footerTabValue = tabValue === 1 ? 2 : tabValue;
diff --git a/src/teachers-module/pages/LessonDetails.tsx b/src/teachers-module/pages/LessonDetails.tsx
index 2c25c90083..d4fe505eac 100644
--- a/src/teachers-module/pages/LessonDetails.tsx
+++ b/src/teachers-module/pages/LessonDetails.tsx
@@ -20,6 +20,8 @@ import { Capacitor } from '@capacitor/core';
import { ScreenOrientation } from '@capacitor/screen-orientation';
import { useOnlineOfflineErrorMessageHandler } from '../../common/onlineOfflineErrorMessageHandler';
import logger from '../../utility/logger';
+import { parsePath } from 'history';
+
interface LessonDetailsProps {}
type LessonDetailsState = {
course?: TableTypes<'course'>;
@@ -101,9 +103,11 @@ const LessonDetails: React.FC = ({}) => {
});
return;
}
- history.push(
- PAGES.LIVE_QUIZ_GAME + `?lessonId=${lesson.cocos_lesson_id}`,
- {
+ history.push({
+ ...parsePath(
+ PAGES.LIVE_QUIZ_GAME + `?lessonId=${lesson.cocos_lesson_id}`,
+ ),
+ state: {
courseId: course?.id,
lesson: JSON.stringify(lesson),
selectedLesson: selectedLessonMap,
@@ -111,22 +115,25 @@ const LessonDetails: React.FC = ({}) => {
returnState: lessonDetailsReturnState,
source: SOURCE.TEACHER_MODE,
},
- );
+ });
} else {
const playableLessonId = Util.getLessonBundleId(lesson);
if (!playableLessonId) {
return;
}
const parmas = `?courseid=${lesson.cocos_subject_code}&chapterid=${lesson.cocos_chapter_code}&lessonid=${playableLessonId}`;
- history.push(PAGES.LIDO_PLAYER + parmas, {
- lessonId: playableLessonId,
- courseDocId: course?.id,
- course: JSON.stringify(course!),
- lesson: JSON.stringify(lesson),
- selectedLesson: selectedLessonMap,
- from: history.location.pathname + `?${CONTINUE}=true`,
- returnState: lessonDetailsReturnState,
- source: SOURCE.TEACHER_MODE,
+ history.push({
+ ...parsePath(PAGES.LIDO_PLAYER + parmas),
+ state: {
+ lessonId: playableLessonId,
+ courseDocId: course?.id,
+ course: JSON.stringify(course!),
+ lesson: JSON.stringify(lesson),
+ selectedLesson: selectedLessonMap,
+ from: history.location.pathname + `?${CONTINUE}=true`,
+ returnState: lessonDetailsReturnState,
+ source: SOURCE.TEACHER_MODE,
+ },
});
}
};
@@ -256,11 +263,17 @@ const LessonDetails: React.FC = ({}) => {
isBackButton={true}
onButtonClick={() => {
course
- ? history.replace(state.from || PAGES.SEARCH_LESSON, {
- course: course,
- chapterId: chapterId,
+ ? history.replace({
+ ...parsePath(state.from || PAGES.SEARCH_LESSON),
+ state: {
+ course: course,
+ chapterId: chapterId,
+ },
})
- : history.replace(PAGES.HOME_PAGE, { tabValue: 1 });
+ : history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 1 },
+ });
}}
showSideMenu={false}
customText={t('Learning Outcome') ?? 'Learning Outcome'}
@@ -389,11 +402,17 @@ const LessonDetails: React.FC = ({}) => {
assignments={assignmentCount}
onClick={() => {
course
- ? history.replace(PAGES.SHOW_CHAPTERS, {
- course,
- chapterId,
+ ? history.replace({
+ ...parsePath(PAGES.SHOW_CHAPTERS),
+ state: {
+ course,
+ chapterId,
+ },
})
- : history.replace(PAGES.HOME_PAGE, { tabValue: 2 });
+ : history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 2 },
+ });
}}
/>
diff --git a/src/teachers-module/pages/ManageClass.tsx b/src/teachers-module/pages/ManageClass.tsx
index b0771379e6..3e737aee78 100644
--- a/src/teachers-module/pages/ManageClass.tsx
+++ b/src/teachers-module/pages/ManageClass.tsx
@@ -14,6 +14,7 @@ import { useAppSelector } from '../../redux/hooks';
import { RootState } from '../../redux/store';
import { AuthState } from '../../redux/slices/auth/authSlice';
import logger from '../../utility/logger';
+import { parsePath } from 'history';
const CLASS_CREATION_ROLES = [
RoleType.SUPER_ADMIN,
@@ -73,8 +74,11 @@ const ManageClass: React.FC = () => {
!!currentSchoolRole && CLASS_CREATION_ROLES.includes(currentSchoolRole);
const onBackButtonClick = () => {
- history.replace(PAGES.HOME_PAGE, {
- tabValue: 0,
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: {
+ tabValue: 0,
+ },
});
};
useEffect(() => {
@@ -118,7 +122,12 @@ const ManageClass: React.FC = () => {
{canCreate && !isExternalUser && (
{
- history.replace(PAGES.ADD_CLASS, { origin: PAGES.MANAGE_CLASS });
+ history.replace({
+ ...parsePath(PAGES.ADD_CLASS),
+ state: {
+ origin: PAGES.MANAGE_CLASS,
+ },
+ });
}}
/>
)}
diff --git a/src/teachers-module/pages/ManageSchools.tsx b/src/teachers-module/pages/ManageSchools.tsx
index 4cdd1bec29..a0494bb43f 100644
--- a/src/teachers-module/pages/ManageSchools.tsx
+++ b/src/teachers-module/pages/ManageSchools.tsx
@@ -20,6 +20,7 @@ import logger from '../../utility/logger';
import { useAppSelector } from '../../redux/hooks';
import { RootState } from '../../redux/store';
import { AuthState } from '../../redux/slices/auth/authSlice';
+import { parsePath } from 'history';
const PAGE_SIZE = 20;
const SEARCH_DEBOUNCE_MS = 500;
@@ -123,8 +124,11 @@ const ManageSchools: React.FC = () => {
};
const onBackButtonClick = () => {
- history.replace(PAGES.HOME_PAGE, {
- tabValue: 0,
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: {
+ tabValue: 0,
+ },
});
};
diff --git a/src/teachers-module/pages/ReqEditSchool.tsx b/src/teachers-module/pages/ReqEditSchool.tsx
index 109516e6cb..d055e9fec1 100644
--- a/src/teachers-module/pages/ReqEditSchool.tsx
+++ b/src/teachers-module/pages/ReqEditSchool.tsx
@@ -21,6 +21,8 @@ import { schoolUtil } from '../../utility/schoolUtil';
import { useOnlineOfflineErrorMessageHandler } from '../../common/onlineOfflineErrorMessageHandler';
import logger from '../../utility/logger';
import { logAuthDebug } from '../../utility/authDebug';
+import { getAppPathname } from '../../utility/routerLocation';
+import { parsePath } from 'history';
interface LocationState {
school?: SchoolWithRole['school'];
role?: RoleType;
@@ -88,17 +90,19 @@ const ReqEditSchool: React.FC = () => {
};
const onBackButtonClick = () => {
- history.replace(
- prevOrigin === PAGES.DISPLAY_SCHOOLS
- ? PAGES.DISPLAY_SCHOOLS
- : isEditMode && !navigationState
- ? PAGES.SCHOOL_PROFILE
- : PAGES.MANAGE_SCHOOL,
- {
+ history.replace({
+ ...parsePath(
+ prevOrigin === PAGES.DISPLAY_SCHOOLS
+ ? PAGES.DISPLAY_SCHOOLS
+ : isEditMode && !navigationState
+ ? PAGES.SCHOOL_PROFILE
+ : PAGES.MANAGE_SCHOOL,
+ ),
+ state: {
school: school,
role: role,
},
- );
+ });
};
const [profilePic, setProfilePic] = useState(null);
@@ -129,7 +133,7 @@ const ReqEditSchool: React.FC = () => {
logAuthDebug('Navigating to login after teacher school-request logout.', {
source: 'ReqEditSchool.onSignOut',
reason: 'logout_complete_navigate_login',
- from_page: window.location.pathname,
+ from_page: getAppPathname(),
to_page: PAGES.LOGIN,
});
history.replace(PAGES.LOGIN);
diff --git a/src/teachers-module/pages/SchoolUsers.tsx b/src/teachers-module/pages/SchoolUsers.tsx
index b31dbc199d..ad0b2c7fa1 100644
--- a/src/teachers-module/pages/SchoolUsers.tsx
+++ b/src/teachers-module/pages/SchoolUsers.tsx
@@ -9,6 +9,7 @@ import { useHistory, useLocation } from 'react-router-dom';
import { RoleType } from '../../interface/modelInterfaces';
import SchoolUserList from '../components/schoolUsers/SchoolUserList';
import { IonPage } from '@ionic/react';
+import { parsePath } from 'history';
const SchoolUsers: React.FC = () => {
const history = useHistory();
@@ -58,21 +59,30 @@ const SchoolUsers: React.FC = () => {
setSelectedTab(SCHOOL_USERS.PRINCIPALS);
};
const addPrincipal = () => {
- history.replace(PAGES.ADD_PRINCIPAL, {
- school: school,
- role: role,
+ history.replace({
+ ...parsePath(PAGES.ADD_PRINCIPAL),
+ state: {
+ school: school,
+ role: role,
+ },
});
};
const addCoordinator = () => {
- history.replace(PAGES.ADD_COORDINATOR, {
- school: school,
- role: role,
+ history.replace({
+ ...parsePath(PAGES.ADD_COORDINATOR),
+ state: {
+ school: school,
+ role: role,
+ },
});
};
const addSponsor = () => {
- history.replace(PAGES.ADD_SPONSOR, {
- school: school,
- role: role,
+ history.replace({
+ ...parsePath(PAGES.ADD_SPONSOR),
+ state: {
+ school: school,
+ role: role,
+ },
});
};
diff --git a/src/teachers-module/pages/SearchLessons.tsx b/src/teachers-module/pages/SearchLessons.tsx
index b701451bbf..8820bd776e 100644
--- a/src/teachers-module/pages/SearchLessons.tsx
+++ b/src/teachers-module/pages/SearchLessons.tsx
@@ -18,6 +18,7 @@ import ChapterWiseLessons from '../components/ChapterWiseLessons';
import { readAssignmentCartFromStorage } from './AssignmentCartStorage';
import logger from '../../utility/logger';
import AssignedVisibilityToggle from '../components/AssignedVisibilityToggle';
+import { parsePath } from 'history';
type LessonMeta = {
chapterId: string | null;
@@ -654,7 +655,12 @@ const SearchLesson: React.FC = () => {
history.replace(PAGES.HOME_PAGE, { tabValue: 1 })}
+ onButtonClick={() =>
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 1 },
+ })
+ }
customText={t('Search') ?? 'Search'}
schoolName={currentSchool?.name}
className={currentClass?.name}
diff --git a/src/teachers-module/pages/SearchSchool.tsx b/src/teachers-module/pages/SearchSchool.tsx
index dd1e5cee1b..2b604aa707 100644
--- a/src/teachers-module/pages/SearchSchool.tsx
+++ b/src/teachers-module/pages/SearchSchool.tsx
@@ -31,6 +31,7 @@ import { t } from 'i18next';
import { useHistory } from 'react-router';
import { schoolUtil } from '../../utility/schoolUtil';
import Header from '../components/homePage/Header';
+import { parsePath } from 'history';
const PAGE_LIMIT = 50;
@@ -75,9 +76,15 @@ const SearchSchool: FC = () => {
currentUser?.id as string,
);
if (existingRequest?.request_status === STATUS.REQUESTED) {
- history.replace(PAGES.POST_SUCCESS, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.POST_SUCCESS),
+ state: { tabValue: 0 },
+ });
} else {
- history.replace(PAGES.SEARCH_SCHOOL, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.SEARCH_SCHOOL),
+ state: { tabValue: 0 },
+ });
}
};
useEffect(() => {
diff --git a/src/teachers-module/pages/ShowChapters.tsx b/src/teachers-module/pages/ShowChapters.tsx
index cebfb67f06..fd3bc056cc 100644
--- a/src/teachers-module/pages/ShowChapters.tsx
+++ b/src/teachers-module/pages/ShowChapters.tsx
@@ -20,6 +20,7 @@ import {
} from './ShowChaptersLogic';
import logger from '../../utility/logger';
import AssignedVisibilityToggle from '../components/AssignedVisibilityToggle';
+import { parsePath } from 'history';
const ShowChapters: React.FC = () => {
const [currentClass, setCurrentClass] = useState | null>(
@@ -176,14 +177,17 @@ const ShowChapters: React.FC = () => {
lesson: TableTypes<'lesson'>,
chapter: TableTypes<'chapter'>,
) => {
- history.replace(PAGES.LESSON_DETAILS, {
- course: course,
- lesson: lesson,
- chapterId: chapter.id,
- selectedLesson: selectedLesson,
- chapterName: chapter.name,
- gradeName: selectedCourseGrade,
- from: PAGES.SHOW_CHAPTERS,
+ history.replace({
+ ...parsePath(PAGES.LESSON_DETAILS),
+ state: {
+ course: course,
+ lesson: lesson,
+ chapterId: chapter.id,
+ selectedLesson: selectedLesson,
+ chapterName: chapter.name,
+ gradeName: selectedCourseGrade,
+ from: PAGES.SHOW_CHAPTERS,
+ },
});
};
// if (lessonIds !== undefined) {
@@ -387,7 +391,10 @@ const ShowChapters: React.FC = () => {
{
- history.replace(PAGES.HOME_PAGE, { tabValue: 1 });
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 1 },
+ });
}}
customText="Library"
showSearchIcon={true}
diff --git a/src/teachers-module/pages/ShowStudentsInAssignmentPage.tsx b/src/teachers-module/pages/ShowStudentsInAssignmentPage.tsx
index 7454f86b9a..e21a27a65c 100644
--- a/src/teachers-module/pages/ShowStudentsInAssignmentPage.tsx
+++ b/src/teachers-module/pages/ShowStudentsInAssignmentPage.tsx
@@ -6,6 +6,7 @@ import './ShowStudentsInAssignmentPage.css';
import CreateSelectedAssignment from '../components/homePage/assignment/CreateSelectedAssignment';
import { Util } from '../../utility/util';
import logger from '../../utility/logger';
+import { parsePath } from 'history';
const ShowStudentsInAssignmentPage: React.FC = () => {
const [currentUser, setCurrentUser] = useState | null>(
@@ -61,7 +62,10 @@ const ShowStudentsInAssignmentPage: React.FC = () => {
return;
}
if (fromPage === PAGES.QR_ASSIGNMENTS && qrAssignmentNavigationState) {
- history.replace(PAGES.QR_ASSIGNMENTS, qrAssignmentNavigationState);
+ history.replace({
+ ...parsePath(PAGES.QR_ASSIGNMENTS),
+ state: qrAssignmentNavigationState,
+ });
return;
}
history.replace(PAGES.TEACHER_ASSIGNMENT);
diff --git a/src/teachers-module/pages/StudentProfile.tsx b/src/teachers-module/pages/StudentProfile.tsx
index 8aa2756278..89c98c5750 100644
--- a/src/teachers-module/pages/StudentProfile.tsx
+++ b/src/teachers-module/pages/StudentProfile.tsx
@@ -10,6 +10,7 @@ import { Util } from '../../utility/util';
import { subDays } from 'date-fns';
import { useHistory } from 'react-router-dom';
import logger from '../../utility/logger';
+import { parsePath } from 'history';
const StudentProfile: React.FC = () => {
const history = useHistory();
@@ -36,12 +37,15 @@ const StudentProfile: React.FC = () => {
const handleViewProgressClick = () => {
var startDate = subDays(new Date(), 6);
var endDate = new Date();
- history.replace(PAGES.STUDENT_REPORT, {
- student: student,
- startDate: startDate,
- endDate: endDate,
- isStudentProfilePage: true,
- classDoc: tempClass,
+ history.replace({
+ ...parsePath(PAGES.STUDENT_REPORT),
+ state: {
+ student: student,
+ startDate: startDate,
+ endDate: endDate,
+ isStudentProfilePage: true,
+ classDoc: tempClass,
+ },
});
};
@@ -65,7 +69,7 @@ const StudentProfile: React.FC = () => {
};
const onBackButtonClick = () => {
- history.replace(PAGES.CLASS_USERS, currentClass);
+ history.replace({ ...parsePath(PAGES.CLASS_USERS), state: currentClass });
};
const handleUpdateClick = async () => {
diff --git a/src/teachers-module/pages/StudentReport.tsx b/src/teachers-module/pages/StudentReport.tsx
index 6d7e9a792c..77af962228 100644
--- a/src/teachers-module/pages/StudentReport.tsx
+++ b/src/teachers-module/pages/StudentReport.tsx
@@ -13,6 +13,7 @@ import { PAGES, TableTypes } from '../../common/constants';
import { ServiceConfig } from '../../services/ServiceConfig';
import { ClassUtil } from '../../utility/classUtil';
import logger from '../../utility/logger';
+import { parsePath } from 'history';
type StudentReportLocationState = {
student?: TableTypes<'user'>;
@@ -194,20 +195,29 @@ const StudentReport: React.FC = () => {
};
const handleBackButton = () => {
if (isStudentProfilePage) {
- history.replace(PAGES.STUDENT_PROFILE, {
- studentId: student.id,
- classDoc: tempClass,
+ history.replace({
+ ...parsePath(PAGES.STUDENT_PROFILE),
+ state: {
+ studentId: student.id,
+ classDoc: tempClass,
+ },
});
} else if (fromDashboardBand) {
- history.replace(PAGES.HOME_PAGE, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 0 },
+ });
} else {
- history.replace(PAGES.HOME_PAGE, {
- tabValue: 3,
- startDate: locationState.startDate,
- endDate: locationState.endDate,
- selectedType: locationState.selectedType,
- isAssignments: locationState.isAssignments,
- sortType: locationState.sortType,
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: {
+ tabValue: 3,
+ startDate: locationState.startDate,
+ endDate: locationState.endDate,
+ selectedType: locationState.selectedType,
+ isAssignments: locationState.isAssignments,
+ sortType: locationState.sortType,
+ },
});
}
};
diff --git a/src/teachers-module/pages/SubjectSelection.tsx b/src/teachers-module/pages/SubjectSelection.tsx
index 1e07d304aa..dd380fdc4c 100644
--- a/src/teachers-module/pages/SubjectSelection.tsx
+++ b/src/teachers-module/pages/SubjectSelection.tsx
@@ -22,6 +22,7 @@ import { AuthState } from '../../redux/slices/auth/authSlice';
import { RootState } from '../../redux/store';
import logger from '../../utility/logger';
import { getCachedImageSrc } from '../../utility/imageCache';
+import { parsePath } from 'history';
interface CurriculumWithCourses {
curriculum: { id: string; name: string; grade?: string };
@@ -454,22 +455,31 @@ const SubjectSelection: React.FC = () => {
const finalRole: RoleType = userRole ?? RoleType.PRINCIPAL;
if (previousOrigin === PAGES.DISPLAY_SCHOOLS) {
Util.setNavigationState(School_Creation_Stages.CREATE_CLASS);
- history.replace(PAGES.ADD_CLASS, {
- school: currentSchool,
- origin: PAGES.SUBJECTS_PAGE,
+ history.replace({
+ ...parsePath(PAGES.ADD_CLASS),
+ state: {
+ school: currentSchool,
+ origin: PAGES.SUBJECTS_PAGE,
+ },
});
} else if (previousOrigin === PAGES.HOME_PAGE) {
Util.setCurrentSchool(currentSchool!, finalRole);
Util.setCurrentClass(currentClass!);
Util.clearNavigationState();
- history.replace(PAGES.HOME_PAGE, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 0 },
+ });
void Util.validateCurrentSchoolContext();
} else {
if (navigationState?.stage === School_Creation_Stages.CLASS_COURSE) {
Util.setCurrentSchool(currentSchool!, finalRole);
Util.setCurrentClass(currentClass!);
Util.clearNavigationState();
- history.replace(PAGES.HOME_PAGE, { tabValue: 0 });
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 0 },
+ });
void Util.validateCurrentSchoolContext();
}
setIsSelecting(false);
@@ -571,9 +581,12 @@ const SubjectSelection: React.FC = () => {
}
if (navigationState?.stage === School_Creation_Stages.CLASS_COURSE) {
Util.setNavigationState(School_Creation_Stages.CREATE_CLASS);
- history.replace(PAGES.EDIT_CLASS, {
- school: currentSchool,
- classDoc: currentClass,
+ history.replace({
+ ...parsePath(PAGES.EDIT_CLASS),
+ state: {
+ school: currentSchool,
+ classDoc: currentClass,
+ },
});
} else {
paramSchoolId
diff --git a/src/teachers-module/pages/TeacherLibraryAssignmentsLogic.ts b/src/teachers-module/pages/TeacherLibraryAssignmentsLogic.ts
index b1214b1b9e..bc21a9189c 100644
--- a/src/teachers-module/pages/TeacherLibraryAssignmentsLogic.ts
+++ b/src/teachers-module/pages/TeacherLibraryAssignmentsLogic.ts
@@ -12,6 +12,7 @@ import { ServiceConfig } from '../../services/ServiceConfig';
import { Util } from '../../utility/util';
import { TeacherAssignmentPageType } from '../components/homePage/assignment/TeacherAssignment';
import logger from '../../utility/logger';
+import { parsePath } from 'history';
export interface AssignmentLessonItem {
id: string;
@@ -49,7 +50,10 @@ export const useTeacherLibraryAssignmentsLogic = () => {
const currUser = await auth.getCurrentUser();
if (!currentClass?.id || !currUser?.id) {
- history.replace(PAGES.HOME_PAGE, { tabValue: 1 });
+ history.replace({
+ ...parsePath(PAGES.HOME_PAGE),
+ state: { tabValue: 1 },
+ });
return;
}
@@ -225,10 +229,10 @@ export const useTeacherLibraryAssignmentsLogic = () => {
return;
}
- history.replace(
- PAGES.SHOW_STUDENTS_IN_ASSIGNED_PAGE,
- buildAssignmentPayload(),
- );
+ history.replace({
+ ...parsePath(PAGES.SHOW_STUDENTS_IN_ASSIGNED_PAGE),
+ state: buildAssignmentPayload(),
+ });
};
const handleBackButtonClick = () => {
@@ -236,7 +240,7 @@ export const useTeacherLibraryAssignmentsLogic = () => {
history.goBack();
return;
}
- history.replace(PAGES.HOME_PAGE, { tabValue: 1 });
+ history.replace({ ...parsePath(PAGES.HOME_PAGE), state: { tabValue: 1 } });
};
const getSelectedCount = (group: AssignmentCourseGroup): number =>
diff --git a/src/teachers-module/pages/TeacherProfile.tsx b/src/teachers-module/pages/TeacherProfile.tsx
index 3bd5958e23..f18d24b76d 100644
--- a/src/teachers-module/pages/TeacherProfile.tsx
+++ b/src/teachers-module/pages/TeacherProfile.tsx
@@ -5,6 +5,7 @@ import Header from '../components/homePage/Header';
import { IonPage } from '@ionic/react';
import TeacherProfileSection from '../components/addTeacher/TeacherProfileSection';
import { useHistory, useLocation } from 'react-router-dom';
+import { parsePath } from 'history';
const TeacherProfile: React.FC = () => {
const localTeacher = localStorage.getItem(CURRENT_TEACHER);
@@ -17,7 +18,10 @@ const TeacherProfile: React.FC = () => {
const { classDoc, school } = location.state || {};
const onBackButtonClick = () => {
- history.replace(`${PAGES.CLASS_USERS}?tab=Teachers`, classDoc);
+ history.replace({
+ ...parsePath(`${PAGES.CLASS_USERS}?tab=Teachers`),
+ state: classDoc,
+ });
};
return (
diff --git a/src/teachers-module/pages/UserProfile.tsx b/src/teachers-module/pages/UserProfile.tsx
index bd15147e32..c902389de6 100644
--- a/src/teachers-module/pages/UserProfile.tsx
+++ b/src/teachers-module/pages/UserProfile.tsx
@@ -11,6 +11,7 @@ import Header from '../components/homePage/Header';
import ProfileDetails from '../components/library/ProfileDetails';
import UserProfileSection from '../components/UserProfileSection';
import './UserProfile.css';
+import { parsePath } from 'history';
const UserProfile: React.FC = () => {
const history = useHistory();
@@ -154,7 +155,7 @@ const UserProfile: React.FC = () => {
const placeholderImgBase64 = 'data:image/png;base64,....';
const onBackButtonClick = () => {
- history.replace(PAGES.HOME_PAGE, { tabValue: 0 });
+ history.replace({ ...parsePath(PAGES.HOME_PAGE), state: { tabValue: 0 } });
};
return (
diff --git a/src/tests/__mocks__/@ionic/react-router.tsx b/src/tests/__mocks__/@ionic/react-router.tsx
index 7e47f9c755..4d41e9e0f4 100644
--- a/src/tests/__mocks__/@ionic/react-router.tsx
+++ b/src/tests/__mocks__/@ionic/react-router.tsx
@@ -1,8 +1,22 @@
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
-export const IonReactRouter: React.FC<{ children: React.ReactNode }> = ({
- children,
-}) => {
- return
{children};
+const getInitialEntry = () => {
+ if (typeof window === 'undefined') {
+ return '/';
+ }
+
+ if (window.location.hash.startsWith('#/')) {
+ return window.location.hash.slice(1);
+ }
+
+ return '/';
};
+
+const MockIonicRouter: React.FC<{ children: React.ReactNode }> = ({
+ children,
+}) => (
+
{children}
+);
+
+export const IonReactHashRouter = MockIonicRouter;
diff --git a/src/utility/logger.ts b/src/utility/logger.ts
index 7ba91ecedc..b2036234d5 100644
--- a/src/utility/logger.ts
+++ b/src/utility/logger.ts
@@ -4,6 +4,7 @@ import {
NativeBridgePayload,
sanitizeNativeBridgePayload,
} from './safeNativeBridgePayload';
+import { getAppPathname } from './routerLocation';
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
type LogMethod = 'debug' | 'info' | 'warn' | 'error';
@@ -54,14 +55,15 @@ const IS_NATIVE =
!!(window as any).Capacitor &&
(window as any).Capacitor.getPlatform() !== 'web';
-let cachedPage: string | undefined = HAS_WINDOW
- ? window.location.pathname
- : undefined;
+let cachedPage: string | undefined = HAS_WINDOW ? getAppPathname() : undefined;
if (HAS_WINDOW) {
- window.addEventListener('popstate', () => {
- cachedPage = window.location.pathname;
- });
+ const updateCachedPage = () => {
+ cachedPage = getAppPathname();
+ };
+
+ window.addEventListener('popstate', updateCachedPage);
+ window.addEventListener('hashchange', updateCachedPage);
}
/**
diff --git a/src/utility/routerLocation.test.ts b/src/utility/routerLocation.test.ts
new file mode 100644
index 0000000000..198a0b7449
--- /dev/null
+++ b/src/utility/routerLocation.test.ts
@@ -0,0 +1,41 @@
+import {
+ buildHashAppUrl,
+ normalizeInitialHashRouteEntry,
+} from './routerLocation';
+
+describe('routerLocation', () => {
+ afterEach(() => {
+ window.history.replaceState({}, '', '/');
+ });
+
+ test('buildHashAppUrl creates shareable hash-router URLs', () => {
+ const url = buildHashAppUrl(
+ {
+ pathname: '/assignment',
+ search: '?batch_id=batch-1&source=teacher',
+ },
+ 'https://chimple.cc',
+ );
+
+ expect(url.toString()).toBe(
+ 'https://chimple.cc/#/assignment?batch_id=batch-1&source=teacher',
+ );
+ });
+
+ test('normalizeInitialHashRouteEntry rewrites known pathname routes', () => {
+ window.history.replaceState({}, '', '/join-class?classCode=123');
+
+ expect(normalizeInitialHashRouteEntry()).toBe(true);
+ expect(window.location.pathname).toBe('/');
+ expect(window.location.hash).toBe('#/join-class?classCode=123');
+ });
+
+ test('normalizeInitialHashRouteEntry leaves root entry unchanged', () => {
+ window.history.replaceState({}, '', '/?page=/join-class');
+
+ expect(normalizeInitialHashRouteEntry()).toBe(false);
+ expect(window.location.pathname).toBe('/');
+ expect(window.location.search).toBe('?page=/join-class');
+ expect(window.location.hash).toBe('');
+ });
+});
diff --git a/src/utility/routerLocation.ts b/src/utility/routerLocation.ts
new file mode 100644
index 0000000000..7539ea2c5e
--- /dev/null
+++ b/src/utility/routerLocation.ts
@@ -0,0 +1,210 @@
+import { createPath, parsePath } from 'history';
+
+import { BASE_NAME, PAGES } from '../common/constants';
+
+type AppLocationParts = {
+ pathname: string;
+ search: string;
+ hash: string;
+};
+
+const normalizePathname = (pathname: string) => {
+ const trimmed = pathname.replace(/\/+$/, '');
+ return trimmed || '/';
+};
+
+const normalizeSearch = (search: string) => {
+ if (!search || search === '?') {
+ return '';
+ }
+
+ return search.startsWith('?') ? search : `?${search}`;
+};
+
+const normalizeHash = (hash: string) => {
+ if (!hash || hash === '#') {
+ return '';
+ }
+
+ return hash.startsWith('#') ? hash : `#${hash}`;
+};
+
+const normalizeBasename = (basename: string) => {
+ if (!basename || basename === '/') {
+ return '';
+ }
+
+ const trimmed = basename.replace(/\/+$/, '');
+ return trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
+};
+
+const hasBasename = (path: string, basename: string) =>
+ path.toLowerCase().indexOf(basename.toLowerCase()) === 0 &&
+ '/?#'.includes(path.charAt(basename.length));
+
+const stripBasename = (pathname: string) => {
+ const basename = normalizeBasename(BASE_NAME);
+ if (!basename || !hasBasename(pathname, basename)) {
+ return pathname;
+ }
+
+ return pathname.slice(basename.length) || '/';
+};
+
+const addBasename = (pathname: string) => {
+ const basename = normalizeBasename(BASE_NAME);
+ if (!basename) {
+ return pathname;
+ }
+
+ return pathname === '/' ? basename : `${basename}${pathname}`;
+};
+
+const pageRoutes =
+ PAGES && typeof PAGES === 'object' ? (PAGES as Record
) : {};
+
+const KNOWN_APP_ROUTE_PATHS = new Set(
+ Object.values(pageRoutes)
+ .map((path) => String(path))
+ .filter((path) => path.startsWith('/') && path !== '/' && path !== '/#'),
+);
+
+const isHashRoutedUrl = () =>
+ typeof window !== 'undefined' && window.location.hash.startsWith('#/');
+
+const getHashRoutePath = () => {
+ if (typeof window === 'undefined') {
+ return '/';
+ }
+
+ const rawHash = window.location.hash.replace(/^#/, '');
+ if (!rawHash) {
+ return '/';
+ }
+
+ return rawHash.startsWith('/') ? rawHash : `/${rawHash}`;
+};
+
+const readCurrentAppLocation = (): AppLocationParts => {
+ if (typeof window === 'undefined') {
+ return { pathname: '/', search: '', hash: '' };
+ }
+
+ const parsed = isHashRoutedUrl()
+ ? parsePath(getHashRoutePath())
+ : parsePath(
+ `${window.location.pathname}${window.location.search}${window.location.hash}`,
+ );
+
+ return {
+ pathname: normalizePathname(
+ isHashRoutedUrl()
+ ? parsed.pathname || '/'
+ : stripBasename(parsed.pathname || '/'),
+ ),
+ search: normalizeSearch(parsed.search || ''),
+ hash: normalizeHash(parsed.hash || ''),
+ };
+};
+
+const withDefaults = (
+ nextLocation: Partial = {},
+): AppLocationParts => {
+ const current = readCurrentAppLocation();
+
+ return {
+ pathname: normalizePathname(nextLocation.pathname ?? current.pathname),
+ search: normalizeSearch(nextLocation.search ?? current.search),
+ hash: normalizeHash(nextLocation.hash ?? current.hash),
+ };
+};
+
+export const getAppLocation = () => readCurrentAppLocation();
+
+export const getAppPathname = () => readCurrentAppLocation().pathname;
+
+export const getAppSearch = () => readCurrentAppLocation().search;
+
+export const getAppHash = () => readCurrentAppLocation().hash;
+
+export const getAppSearchParams = () => new URLSearchParams(getAppSearch());
+
+export const getAppPath = () => createPath(readCurrentAppLocation());
+
+export const buildHashAppUrl = (
+ nextLocation: Partial = {},
+ origin?: string,
+) => {
+ const fallbackOrigin =
+ origin ??
+ (typeof window !== 'undefined'
+ ? window.location.origin
+ : 'http://localhost');
+ const url = new URL(addBasename('/'), fallbackOrigin);
+
+ url.hash = createPath({
+ pathname: normalizePathname(nextLocation.pathname ?? '/'),
+ search: normalizeSearch(nextLocation.search ?? ''),
+ hash: normalizeHash(nextLocation.hash ?? ''),
+ });
+
+ return url;
+};
+
+export const buildAppUrl = (nextLocation: Partial = {}) => {
+ if (typeof window === 'undefined') {
+ return new URL('http://localhost/');
+ }
+
+ const location = withDefaults(nextLocation);
+ const url = new URL(window.location.href);
+
+ if (isHashRoutedUrl()) {
+ url.hash = createPath({
+ pathname: location.pathname,
+ search: location.search,
+ hash: location.hash,
+ });
+ } else {
+ url.pathname = addBasename(location.pathname);
+ url.search = location.search;
+ url.hash = location.hash;
+ }
+
+ return url;
+};
+
+export const getAppHref = () => buildAppUrl().toString();
+
+export const normalizeInitialHashRouteEntry = () => {
+ if (typeof window === 'undefined' || isHashRoutedUrl()) {
+ return false;
+ }
+
+ const legacyPathname = normalizePathname(
+ stripBasename(window.location.pathname || '/'),
+ );
+
+ if (!KNOWN_APP_ROUTE_PATHS.has(legacyPathname)) {
+ return false;
+ }
+
+ const rewrittenUrl = buildHashAppUrl({
+ pathname: legacyPathname,
+ search: window.location.search,
+ hash: window.location.hash,
+ });
+
+ window.history.replaceState(
+ window.history.state,
+ '',
+ rewrittenUrl.toString(),
+ );
+ return true;
+};
+
+export const replaceAppUrl = (nextLocation: Partial) => {
+ const url = buildAppUrl(nextLocation);
+ window.history.replaceState(window.history.state, '', url.toString());
+ return url;
+};
diff --git a/src/utility/schoolUtil.ts b/src/utility/schoolUtil.ts
index 24569055f2..b0be7a6a7b 100644
--- a/src/utility/schoolUtil.ts
+++ b/src/utility/schoolUtil.ts
@@ -14,6 +14,7 @@ import { store } from '../redux/store';
import { ServiceConfig } from '../services/ServiceConfig';
import { logAuthDebug } from './authDebug';
import logger from './logger';
+import { getAppPathname, replaceAppUrl } from './routerLocation';
import { Util } from './util';
export class schoolUtil {
@@ -142,14 +143,10 @@ export class schoolUtil {
logAuthDebug('School relogin succeeded, redirecting to select mode.', {
source: 'schoolUtil.trySchoolRelogin',
reason: 'school_relogin_success',
- from_page: window.location.pathname,
+ from_page: getAppPathname(),
to_page: PAGES.SELECT_MODE,
});
- window.history.replaceState(
- window.history.state,
- '',
- PAGES.SELECT_MODE.toString(),
- );
+ replaceAppUrl({ pathname: PAGES.SELECT_MODE, search: '', hash: '' });
return true;
} else {
@@ -157,14 +154,10 @@ export class schoolUtil {
logAuthDebug('School relogin failed, redirecting to login.', {
source: 'schoolUtil.trySchoolRelogin',
reason: 'school_relogin_failed_user_not_found',
- from_page: window.location.pathname,
+ from_page: getAppPathname(),
to_page: PAGES.LOGIN,
});
- window.history.replaceState(
- window.history.state,
- '',
- PAGES.LOGIN.toString(),
- );
+ replaceAppUrl({ pathname: PAGES.LOGIN, search: '', hash: '' });
return false;
}
} catch (error) {
diff --git a/src/utility/util.ts b/src/utility/util.ts
index c40700d29c..63d79c1ae5 100644
--- a/src/utility/util.ts
+++ b/src/utility/util.ts
@@ -124,6 +124,12 @@ import logger from './logger';
import type { StickerBookModalData } from '../components/learningPathway/StickerBookPreviewModal';
import { AudioUtil } from './AudioUtil';
import { replaceWithNavigationTarget } from '../helper/navigation/NavigationHandler';
+import {
+ getAppPathname,
+ getAppSearchParams,
+ replaceAppUrl,
+} from './routerLocation';
+import { parsePath } from 'history';
type LessonBundleDownloadOptions = {
lessonId: string;
@@ -1097,8 +1103,8 @@ export class Util {
});
await FirebaseAnalytics.setScreenName({
- screenName: window.location.pathname,
- nameOverride: window.location.pathname,
+ screenName: getAppPathname(),
+ nameOverride: getAppPathname(),
});
await FirebaseAnalytics.logEvent({
@@ -1147,8 +1153,8 @@ export class Util {
//Setting Screen Name
await FirebaseAnalytics.setScreenName({
- screenName: window.location.pathname,
- nameOverride: window.location.pathname,
+ screenName: getAppPathname(),
+ nameOverride: getAppPathname(),
});
}
@@ -1159,8 +1165,9 @@ export class Util {
logger.info('[Lifecycle] App state changed', { isActive });
// Handling app state changes (reloading pages, updating URLs, etc.)
- const url = new URL(window.location.toString());
- const urlParams = new URLSearchParams(window.location.search);
+ const currentPath = getAppPathname();
+ const continueValue = getAppSearchParams().get(CONTINUE);
+ const urlParams = getAppSearchParams();
if (!!urlParams.get(CONTINUE)) {
urlParams.delete(CONTINUE);
}
@@ -1172,29 +1179,37 @@ export class Util {
if (isActive) {
if (
Capacitor.isNativePlatform() &&
- url.searchParams.get(CONTINUE) === 'true' &&
- url.pathname !== PAGES.LOGIN &&
- url.pathname !== PAGES.EDIT_STUDENT
+ continueValue === 'true' &&
+ currentPath !== PAGES.LOGIN &&
+ currentPath !== PAGES.EDIT_STUDENT
) {
if (
- url.pathname === PAGES.DISPLAY_SUBJECTS ||
- url.pathname === PAGES.DISPLAY_CHAPTERS
+ currentPath === PAGES.DISPLAY_SUBJECTS ||
+ currentPath === PAGES.DISPLAY_CHAPTERS
) {
- url.searchParams.set('isReload', 'true');
+ urlParams.set('isReload', 'true');
}
- url.searchParams.delete(CONTINUE);
- window.history.replaceState(window.history.state, '', url.toString());
+ urlParams.delete(CONTINUE);
+ replaceAppUrl({
+ pathname: currentPath,
+ search: urlParams.toString() ? `?${urlParams.toString()}` : '',
+ hash: '',
+ });
window.location.reload();
} else {
- url.searchParams.set('isReload', 'true');
- url.searchParams.delete(CONTINUE);
- window.history.replaceState(window.history.state, '', url.toString());
+ urlParams.set('isReload', 'true');
+ urlParams.delete(CONTINUE);
+ replaceAppUrl({
+ pathname: currentPath,
+ search: urlParams.toString() ? `?${urlParams.toString()}` : '',
+ hash: '',
+ });
}
}
};
public static setPathToBackButton(path: string, history: any) {
- const url = new URLSearchParams(window.location.search);
+ const url = getAppSearchParams();
if (url.get(CONTINUE)) {
history.replace(`${path}?${CONTINUE}=true`);
} else {
@@ -1780,7 +1795,7 @@ export class Util {
// Determine target page for logging
let destinationPage = '';
const newSearchParams = new URLSearchParams(url.search);
- const currentParams = new URLSearchParams(window.location.search);
+ const currentParams = getAppSearchParams();
currentParams.set('classCode', newSearchParams.get('classCode') ?? '');
currentParams.set('page', PAGES.JOIN_CLASS);
const currentStudent = Util.getCurrentStudent();
@@ -2234,10 +2249,13 @@ export class Util {
origin: PAGES,
classId?: string,
) {
- history.replace(redirectPage, {
- classId: classId,
- origin: origin,
- isSelect: true,
+ history.replace({
+ ...parsePath(redirectPage),
+ state: {
+ classId: classId,
+ origin: origin,
+ isSelect: true,
+ },
});
}
public static async handleClassAndSubjects(
@@ -2251,18 +2269,24 @@ export class Util {
const schoolCourses = await api.getCoursesBySchoolId(schoolId);
if (schoolCourses.length === 0) {
this.setNavigationState(School_Creation_Stages.SCHOOL_COURSE);
- history.replace(PAGES.SUBJECTS_PAGE, {
- schoolId: schoolId,
- origin: originPage,
- isSelect: true,
+ history.replace({
+ ...parsePath(PAGES.SUBJECTS_PAGE),
+ state: {
+ schoolId: schoolId,
+ origin: originPage,
+ isSelect: true,
+ },
});
return;
}
const fetchedClasses = await api.getClassesForSchool(schoolId, userId);
if (fetchedClasses.length === 0) {
- history.replace(PAGES.ADD_CLASS, {
- school: { id: schoolId },
- origin: originPage,
+ history.replace({
+ ...parsePath(PAGES.ADD_CLASS),
+ state: {
+ school: { id: schoolId },
+ origin: originPage,
+ },
});
return;
}