This middleware does a few interesting things:
- Ensures a
urlshape in the zustand store, where we'll store URL information. - Assumes we will be storing our
urlstate slice in the?statesearch parameter after it has been stringified and base 64 encoded. - On creation, decodes stores state from the
?statesearch parameter into theurlslice of our store. - After each state update, updates the
?statesearch parameter with the newurlstate slice. - Sets up an event listener that listens for
popstateand re-decodes the state from the URL into our store.