Skip to content

Commit

Permalink
fix: regExp
Browse files Browse the repository at this point in the history
  • Loading branch information
mjulstein committed Jul 26, 2022
1 parent f64c6b9 commit f3ce986
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/altinn-app-frontend/src/common/hooks/useFormLayoutHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ function formLayoutHistory({
history.location,
pathToRoute,
);
const browserIsOnRootPath =
!pageIdFromLocation || pageIdFromLocation === pathToRoute;
const browserIsOnRootPath = pageIdFromLocation === '';
if (renderedPageId) {
// When the application has rendered a view and the location path should reflect this.
if (browserIsOnRootPath) {
// The location path should be changed to the rendered page
history.replace(`${pathToRoute}/${renderedPageId}`);
return;
}
if (renderedPageId !== pageIdFromLocation) {
// Put the rendered pageId in the path
history.push(`${pathToRoute}/${renderedPageId}`);
}
return listenForHistoryAction(
Expand All @@ -95,12 +96,15 @@ function formLayoutHistory({
);
}
if (!browserIsOnRootPath) {
// Render the view correlating to the path
// The application has not rendered a view and a request is sent for a specific page. I.e. direct link.
renderFunc({ newView: pageIdFromLocation });
}
}

function getPageIdFromLocation({ pathname }, removePath) {
if (pathname === removePath) {
return '';
}
return pathname.replace(`${removePath}/`, '');
}

Expand Down

0 comments on commit f3ce986

Please sign in to comment.