diff --git a/app/plugins/views.plugin.js b/app/plugins/views.plugin.js index c1e3aec8f8..80beecf881 100644 --- a/app/plugins/views.plugin.js +++ b/app/plugins/views.plugin.js @@ -91,6 +91,8 @@ function context (request) { return { // `assetPath` is referred to in layout.njk as the path to get static assets like client-side javascript assetPath: '/assets', + // this is the url of where the request came from. We use it to generate back links in our pages + referrer: request.info.referrer, auth: { authenticated: request.auth.isAuthenticated, authorized: request.auth.isAuthorized, diff --git a/app/views/includes/back-link.njk b/app/views/includes/back-link.njk new file mode 100644 index 0000000000..a6192c3165 --- /dev/null +++ b/app/views/includes/back-link.njk @@ -0,0 +1,11 @@ +{% if referrer %} + {% set backlink = referrer %} +{% else %} + {% set backlink = 'javascript:history.back()' %} +{% endif %} +{{ + govukBackLink({ + text: "Back", + href: backlink + }) +}}