diff --git a/helpers/previous-page.js b/helpers/previous-page.js index 29acaa369..b8c104dcb 100644 --- a/helpers/previous-page.js +++ b/helpers/previous-page.js @@ -13,18 +13,24 @@ const checkConditions = (conditions, session) => { } const previousPage = (url, session) => { + console.log('finding porevious page') const pages = Object.keys(COMPONENT_FORM_PAGES) const [currentPage, subpage] = url.split('/').slice(1) // split the url to get the page and subpage const currentPageIndex = pages.findIndex((page) => currentPage.endsWith(page)) + console.log(`current page index: ${currentPageIndex}`) // Check if there are subpages in the session for the current page - if (subpage && Number.isInteger(Number(subpage)) && subpage > 1) { - return `${urlRoot}/${currentPage}/${subpage - 1}` + if (subpage && Number.isInteger(Number(subpage))) { + if(subpage > 1) { + return `${urlRoot}/${currentPage}/${subpage - 1}` + } + + return `${urlRoot}/${currentPage}` } for (let i = currentPageIndex - 1; i >= 0; i--) { const page = pages[i] - const conditions = COMPONENT_FORM_PAGES[page] + const conditions = COMPONENT_FORM_PAGES[page]?.conditions || {} const shouldShowPage = checkConditions(conditions, session) if (shouldShowPage) { diff --git a/views/common/base.njk b/views/common/base.njk index 27c2a3fcd..fda6da5c1 100644 --- a/views/common/base.njk +++ b/views/common/base.njk @@ -491,8 +491,9 @@