Skip to content
New issue

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

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

Already on GitHub? # to your account

[Need advice] Capture fragment from URI #6

Open
Rizary opened this issue Aug 19, 2018 · 1 comment
Open

[Need advice] Capture fragment from URI #6

Rizary opened this issue Aug 19, 2018 · 1 comment
Labels

Comments

@Rizary
Copy link

Rizary commented Aug 19, 2018

Hi, when I have link to some blog post /#News/August/01/08/2019/big-announcement-to-tell, what is the best possible way to get each of fragment like "August" or "2019".

Or can we just redirect to /#News and parse August/01/08/2019/big-announcement-to-tell by our self?

@3noch
Copy link
Owner

3noch commented Aug 20, 2018

There are several ways, depending on what you want to do. If you want to get each fragment and build your page top-down, you can use the standard withRoute function and match on each component:

withRoute $ \case ->
  Just "News" -> withRoute $ \day ->
    withRoute $ \month ->
      withRoute $ \year ->
        withRoute $ \name ->
          --build page with all these pieces

If you want them all at once you can just use allRouteSegments which is a Dynamic t [Text] (in this case) and you can build DOM with normal reflex combinators over this dynamic. For example:

fullPath <- allRouteSegments
month <- holdUniqDyn $ fullPath <&> (!! 3) -- Beware: (!!) is partial

@3noch 3noch added the question label Aug 22, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants