rgrempel / elm-route-url

Router for single-page-apps in Elm
http://package.elm-lang.org/packages/rgrempel/elm-route-url/latest
MIT License
196 stars 16 forks source link

Get/ Set value from/ to query string #5

Closed amitaibu closed 8 years ago

amitaibu commented 8 years ago

Sometimes it makes more sense to have query strings mapped to the actions instead of actual arguments (e.g. when filtering search using faceted search)

amitaibu commented 8 years ago

(updated title)

rgrempel commented 8 years ago

I took a quick look at this, and it turns out that it will be a little more complex than I realized.

At the moment, elm-history provides access to window.location.pathname and window.location.hash, but not window.location.search. So, given a URL like:

http://www.apple.com/some/path?query=7#anchor

... elm-history will give us access to "/some/path" and "#anchor", but nothing else.

If https://github.com/elm-lang/package.elm-lang.org/pull/124 gets accepted, then I can enhance elm-history so that it provides access to window.location.search etc. Otherwise, we won't be able to do it without using native code here.

amitaibu commented 8 years ago

ping. Are you still in elm-land ? :)

rgrempel commented 8 years ago

Ah, indeed, here I am!

I have been a little distracted, but there has been progress in elm-history, as @liamcurry has contributed some code to get the full href in a signal.

Though, now that I think about it some more, we'll actually need some code to set the full href as well, or at least as much of it as the HTML5 API allows. But that isn't hard -- I'll write something up for that now.

Once that's done, I need to re-architect elm-route-hash a little so that the current method of parsing is just one option -- so people can get and set full URLs.

rgrempel commented 8 years ago

I'm not sure what I was thinking ... the History module will already allow us to write the query string via setPath or replacePath. So, that's all in place ... I just need to modify elm-route-hash to use it.

amitaibu commented 8 years ago

:+1:

rgrempel commented 8 years ago

This will be implemented for elm-route-hash 2.0, for Elm 0.17.

rgrempel commented 8 years ago

This is now available in the published version 2.0.0 of elm-route-url.