Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle hash in Routing.Match #60

Open
rnons opened this issue Sep 13, 2018 · 5 comments
Open

How to handle hash in Routing.Match #60

rnons opened this issue Sep 13, 2018 · 5 comments

Comments

@rnons
Copy link
Contributor

rnons commented Sep 13, 2018

I have a route like this

myRoute =
  root *> oneOf
  [ RegionRoute <$> (lit "region" *> regionMatcher)
  ]

data Region = West | East

regionMatcher :: Match Region

When using Routing.PushState.matches, /region/west will match, but /region/west#hash will fail. I understand my regionMatcher failed to parse west#hash as Region.

I ended up dropping the hash before hand.
myMatch = matchesWith <<< matchWith (unsafeDecodeURIComponent <<< String.takeWhile (_ /= String.codePointFromChar '#'))

Wondering is there a better way to handle this?

@natefaubion
Copy link
Collaborator

Hi, thanks for your question. I would recommend https://discourse.purescript.org/ as a better outlet for Q&A type stuff. It will get more visibility, and is more likely to get an answer than an issue tracker, which is generally for bugs/requests.

@natefaubion
Copy link
Collaborator

Otherwise, it's hard to say without knowing what regionMatcher is. If you could post a minimal, runnable reproduction with expected vs actual results, it would be much easier to offer a suggestion.

@rnons
Copy link
Contributor Author

rnons commented Oct 1, 2018

Thanks for response. I made a reproduction https://github.com/rnons/purescript-routing-issue-60

image

@natefaubion
Copy link
Collaborator

Unfortunately, the internal parser representation makes no consideration for hashes. https://github.com/slamdata/purescript-routing/blob/c11efec0f5f992f86c907de791826271e43ebd5d/src/Routing/Types.purs#L8

I think this is because the library was originally for hash-based routing only, which does not usually cater to hashes within a hash. The parser splits on ? and /, so it is seeing west#abc as a single atom.

@natefaubion
Copy link
Collaborator

natefaubion commented Oct 1, 2018

For now, I would do what you are doing, which is stripping the hash.

I've been working on an alternative parser/printer library which should be able to interface with Routing.PushState and addresses your issue, but I have not had the time yet to write docs and release. If you are brave enough to try it, I would welcome feedback. https://github.com/natefaubion/purescript-routing-duplex. It has a cute DSL which I haven't committed to yet :D https://github.com/natefaubion/purescript-routing-duplex/blob/94dd7e4ae10c23b19949331e9515f98d3d3006a7/test/Main.purs#L44-L62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants