Skip to content

Commit

Permalink
Fixes an issue with styling links
Browse files Browse the repository at this point in the history
When visiting the links example page, if you had previously visited the
home page then the unvisited link and visited link example looked identical.
This commit passes a random number to the view. The view adds the randomId
to the href as a hash.

Co-authored-by: Nick Colley <nick.colley@digital.cabinet-office.gov.uk>
  • Loading branch information
aliuk2012 and NickColley committed May 2, 2019
1 parent 67fd864 commit 3779e45
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ module.exports = (options) => {

// Example view
app.get('/examples/:example', function (req, res, next) {
res.render(`${req.params.example}/index`, function (error, html) {
// Passing a random number used for the links so that they will be unique and not display as "visited"
const randomPageHash = (Math.random() * 1000000).toFixed()
res.render(`${req.params.example}/index`, { randomPageHash }, function (error, html) {
if (error) {
next(error)
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/views/examples/links/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

{% for state_description, state_class in states %}
<p class="govuk-body">
<a href="/" class="govuk-link {{ variant_class }} {{ state_class }}">
<a href="/#{{ randomPageHash }}" class="govuk-link {{ variant_class }} {{ state_class }}">
{{ state_description}}
</a>
</p>
Expand Down

0 comments on commit 3779e45

Please sign in to comment.