Skip to content

Instantly share code, notes, and snippets.

@sporto
Last active May 13, 2020 23:32
Show Gist options
  • Save sporto/4374996c6a119faedc936b40e25c48ae to your computer and use it in GitHub Desktop.
Save sporto/4374996c6a119faedc936b40e25c48ae to your computer and use it in GitHub Desktop.
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.

back-to

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