Skip to content

Instantly share code, notes, and snippets.



Last active May 13, 2020
What would you like to do?
Back to issue

The problem

There are several pages in our app where users arrive from different places.

e.g. Page A -> Page C Page B -> Page C

In Page C we want to show a link back to the previous page. E.g.

<- Back To A or <- Back to B.


Our current solution

The way we are doing it (using the query string):

  • We add a backTo and backToLabel keys in the query string e.g. /pageC?backTo=/pageA
  • We use those keys for showing the back label and adding the back link

This works ok, but is very brittle:

These query keys may remain in the URL, so if you arrive to a page with those keys there, we end up showing the wrong "back to" link. We should have clearer those keys, but is hard to do it consistently from all the inbound links to that page.

We cannot simply clear the keys after arriving at the page. Because the view uses that. If we remove the keys, then the view will show the default "back to" link.

Using history

Another possible way we discussed with history:

Use history.back().

The issues with this are:

  • We cannot print a different label for the back link e.g. <- Back to B
  • If you arrive to this page via a pasted URL, the link will take you outside Spotlight, we want this back to links to always go to a page in the app.
  • This breaks for sub navigation. We still want the navigation at the top to go the the previous main page (not the previous sub page)

Another possible way

Every link in the app needs to be generated by a central function, this function either adds the backTo or clears the backTo depending on the arguments.This also will break for sub navigation.

Any ideas on how to better handle this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.