From 417481464065233a0e485fdbccf8f0ba2a9c610e Mon Sep 17 00:00:00 2001 From: Chris Pymm Date: Wed, 21 May 2025 17:03:06 +0100 Subject: [PATCH] docs(contributions): fix back link not appearing, and fix previous page for /1 routes --- helpers/previous-page.js | 12 +++++++++--- views/common/base.njk | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) 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 @@
-
{% block content %} - {{ content | safe }} +
+ {% block content %} + {{ content | safe }} {% endblock %}