In most of the website, there is always a “back” to previous button. I am wondering they are usually implemented.
Basically I am building a site with more than 5 levels page depth. As an example, page level goes like:
Advance Search => Search Result => Search Details => Apply For Job => Save Job
I need to make sure that user can navigate back to it’s previous level above, so from “search Details”, they should be able to click back and then goes back to the “Search Result” page with all its previous search criteria preserved.
I am currently storing the “back url” as part of the query string paramter and append the url as user dives in deeper. The issue with this is that when as user dives in more than 3 levels, the url get really long and messy.
What would be the best practice for asp.net MVC apps to deal with this kind of issue?
In an old web development platform I have used (several years back), this was solved using a built in function. The idea was that the server maintained some sort of internal collection of urls and mapped those to simple numbers. When you added a new url to the collection, the server would first check if that exact url was already present and if so just return the associated number. If the url you were adding was new, it would be added and a new number would be returned.
A couple of samples to illustrate… Let’s assume the user starts out at page:
I’ll referr to this page a “Page 1”. After adding the criteria to search for, the user will be shown the reuslts on page:
I’ll call this “Page 2”. On this page the user can click open a specific result and get to page:
I’ll call that “Page 3”.
To have the “back to previous” functionality for pages 2 and 3, they would need to be opened with one additional query parameter. When page 1 is generating the url for page 2, the server would call the utility method
SaveUrl()(on some suitable class) and append the result to the querystring so the url for page 2 becomes:Notice the new
return_url=1query parameter. Page 2 would then use the correspondingGetReturnUrl(1)method to fetch the url to use in the “back to previous” link. This call would bring back the url that was added previously, which would behttp://foo.bar.com/search/.Going forward from page 2 to page 3 would also involve adding a new querystring parameter using the same
SaveUrl(). The new url to page 3 would then be:On page 3, the “back to previous” page url would be fetched using
GetReturnUrl(2), which would give backhttp://foo.bar.com/search/results?jobTitle=CEO&etc&etc&return_url=1.So this system works by storing the url of the current page and supplying that in the url to the next page. And since the url for the current page contains a reference to the current page’s previous page in the form of the query parameter, the back to previous trail is maintained.
I thought I would explain this because I think it’s a smart way to handle the back to previous trail. I’m not claiming that it’s any sort of industry standard or best practise though…
Edit: Some thoughts and considerations regarding this approach.
Pros:
Cons: