Elm url routing advice

Hi, I have the basics down with elm, but now that I am making a web app I got stuck at the routing. I can do basic url routing, but what I want is the Home Route at the top, with a login prompt and once the user has logged in the url must become /username/. In other words, say my app lives at localhost:8000/, that url must route to Home, which I can do already, but how can I make localhost:8000/annie route to the User Route? “annie” is only one user, there can be many such urls, for instance localhost:8000/bob or localhost:8000/peter. How can this be done or is there a better alternative?

Thanks in advance.

Use oneOf

route : Parser (Route -> a) a
route =
    [ map Home top
    , map Admin (s "admin") 
    , map User string 

put all the special links (e.g. /admin, /login or whatever you need) above the User one and everything should be fine.

Thank you, but how wil I then be able to route to another url, say Settings Route, after the user like localhost:8000/bob/settings.

Thanks in advance!

You would add another parser in the list, e.g.

map Settings (string </> s "settings")

where | Settings String gets the username as the parameter.

Thank you very much. I was a bit confused, but now I get it.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.