0

I have a angular view with a list of items and a set of options at the top of the page to filter the items. The user can click an item to view a detail page for the item. I'm using ui-router.

When the user is on a detail and clicks their back button, it returns to the list, but with the filter options reset to default. The filters are too complex to encode in the URL, so I'm wondering: what is the best way to handle this? So far my googling seems to indicate local storage, but I didn't know if this was over-engineering it since I don't want to persist the state all the time, only for the purpose of history (if they navigate to the listing in any other way, I want the defaults). I'm still new to angular so wanted to check with SO if there was a built-in mechanism for this before I go down the rabbit hole.

1
  • Use a service to store the filter settings Commented Jul 28, 2016 at 12:18

1 Answer 1

1

use $cacheFactory instead of localstorage to store filters when changing routes (assuming the details page is on the same angular app)

Sign up to request clarification or add additional context in comments.

2 Comments

Looking at the docs, this does seem the simplest way to handle the storage; but how do I determine if the user is entering the state by hitting the back button vs. click on a menu link?
you can detect if user has clicked back button here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.