elmish / browser

Routing and Navigation for browser apps
https://elmish.github.io/browser
Other
35 stars 20 forks source link

Navigation with different base path? #13

Closed stroborobo closed 6 years ago

stroborobo commented 6 years ago

Description

Hey Elmish team :)

What if you're serving your app from /foo/ instead of just /? Since the Parser passed to Program.toNavigatable is Location -> 'a it cannot know any possible configuration that's inside of your model. I understand that the parser is called before the user's init is called, so there's no initial model yet.

I don't know how to tackle this issue really, for now I put a window.__BASE_PATH__ string into our HTML when the SSR runs and apply it to my parser beforehand so I can cut it out if the location.pathname. For that I copied UrlParser.parseParams and UrlParser.toKeyValuePair btw because they're not public.

Ideas?

Maybe a helper function like UrlParser.parsePathWithPrefix : string -> Location -> 'a would already suffice?

Related information

et1975 commented 6 years ago

If you know the prefix ahead of time you can embed it in the parser combinator: s "foo" </>+ the rest of the combinator if you don't know what it is, you can grab it with str (assuming everything else matches). Ignore it or capture, whatever... makes sense?

et1975 commented 6 years ago

You shouldn't need internal implementation details of the parser, nor parseWithPrefix - just adjust the parser, construct it with the configuration you clearly heave from somewhere if you must, but I think we can close it at this point.