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
.
The way we are doing it (using the query string):
- We add a
backTo
andbackToLabel
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.
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)
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?