When you're creating an SPA in elm, you'll generally need to choose one of two navigation styles:
*1. Allow the address bar to drive your model* The standard Navigation package provides this type of functionality. Your model will respond to changes in the address bar, and your views will (generally) use view links (a tags) to change the address bar. You may have a few sprinkles of manual url changing commands throughout the app for redirection, but for the most part, the majority of url changes are caused by users clicking on html links in your view. The changes flow like this : View --> Address Bar --> Model --> View *2. Allow your model to drive the address bar* In this case, the address bar is simply a reflection of the current state of your model. There is no need to update the address bar manually, because it will keep itself in sync with your model. Try using a routing package like Elm Route Url (http://package.elm-lang.org/packages/rgrempel/elm-route-url/latest). Take a moment and read the package readme. It clearly explains the difference between the 2 styles of routing. If you use this style of navigation, you'll need to build your application in such a way that the navigation is kept within elm and does not require the address bar. For example, rather than including a tag links in your html view to change the url directly, your a-tags or buttons will trigger Msg's that will update your model, and then the address bar will respond to the model change. On Friday, November 25, 2016 at 4:32:50 AM UTC-5, Simon wrote: > > OK, I just don’t quite understand, even while I have working code! > > I have an app where, as the model changes (in particular the value > representing the ‘page’ of my single page app), the Url is updated with > this task > > Navigation.newUrl (toUrl model) > > But as the Url changes, I get a new message from Navigation because of: > > main = > Navigation.programWithFlags > (Routing.urlParser RouteTo) > { init = initWithFlags > , update = Routing.update > , view = view > , subscriptions = subscriptions > } > > When first loading the app, this message is useful and I can use it to > direct to the appropriate opening page. But thereafter this message is > redundant - I already made all the model changes I wanted before and that > caused the Url update. Without some care I even get a loop of each Routing > message causing the > > *I suspect I am missing something rather important, but am not sure what?* > > One option would be to use anchor tags to cause the switch pages, and only > do model changes when I get a RouteTo message, but even then I have some > url changes resulting from the clicking on an element within a page, and I > don’t think that is a place for anchors. (As I use html urls, rather than > # ones I also have to be careful not to let the page get reloaded) > > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
