Basically you have two ways to move around the app (not to use the word 
‘navigate’): 

   - buttons, which will only change the Url if you use Navigation.newUrl 
   after their click Message returns 
   - anchor links that will change the url, but to which you have add a 
   click handler 

on "click" {preventDefault = True, ...} ...

to prevent the page being totally reloaded.

Whenever the url is changed, Navigation will create a new message that you 
can either ignore (if you are updating your model in the original event 
handler), or you wait till the Navigation message hits and take action at 
that stage. Notionally the latter is more elegant, but I don’t think it 
makes much practical difference.

On Thursday, 15 December 2016 18:31:31 UTC+1, ssciantarelli wrote:

Simon (especially),
>
> I'm trying to figure out the exact same thing you were hung up on, can you 
> (or anyone else that knows) please inform on what changes you made to get 
> it working? I've tried doing exactly what you demonstrated in your example 
> and run into the same issues:
> https://gist.github.com/simonh1000/9368f9dbd7f93646207ec27fdf3662a2.
>
> I've also tried using the elm-route-url package, but it seems every time 
> delta2url is called "previous" and "current" are always the same, and never 
> represent what was just clicked. Here's what I tried on that front:
> https://gist.github.com/ssciantarelli/0cba172048f3c9c28754ba4d0ac5a6b1
>
> Finally, I have a StackOverflow post that ultimately explains where I'm 
> going with this if anyone cares to comment/answer over there:
>
> http://stackoverflow.com/questions/41169224/is-it-possible-to-drive-elm-app-with-existing-navigation-constructed-outside-of
>
> Thanks all.
>
> On Sunday, November 27, 2016 at 4:31:27 AM UTC-6, Simon wrote:
>>
>> Erik,
>> thanks so much. I now understand everything. What had confused me was the 
>> example in the Navigation library. Because that uses hash-routing , it can 
>> work with anchors and not need to create Messages and use preventdefault. I 
>> had inferred too much form that about how to work with ordinary links. It 
>> tuend out then that I only needed to make modest changes to my App to make 
>> routing helpful, rather than a massive source of extra, unused messages!
>>
>> Simon
>>
>> On Sunday, 27 November 2016 02:00:08 UTC+1, Erik Lott wrote:
>>>
>>> that should say :
>>> Simon, I'm just glancing at this code, but this page *shouldn't* 
>>>  perform page refreshes at all. It should only fire UrlChange events 
>>> without reload the browser. Am I missing something?
>>>
>>> On Saturday, November 26, 2016 at 5:59:56 PM UTC-5, Erik Lott wrote:
>>>>
>>>> The aim is to get the navigation history ticking along properly without 
>>>>> page refreshes.
>>>>
>>>>
>>>> Simon, I'm just glancing at this code, but this page should perform 
>>>> page refreshes at all. It should only fire UrlChange events without reload 
>>>> the browser. Am I missing something?
>>>>
>>>> On Saturday, November 26, 2016 at 10:54:53 AM UTC-5, Simon wrote:
>>>>>
>>>>> Here is some code to make things more concrete
>>>>> https://gist.github.com/simonh1000/9368f9dbd7f93646207ec27fdf3662a2
>>>>>
>>>>> It is based on the example from the Navigation library, but with the 
>>>>> links changed from # to (I think they are called) HTML5 links.
>>>>>
>>>>> I added an onClick handler to provide a preventDefault as otherwise 
>>>>> the links 404, but with this handler the links don’t navigate instead
>>>>>
>>>>> The aim is to get the navigation history ticking along properly 
>>>>> without page refreshes.
>>>>>
>>>>> I know its possible as I’ve seen it in other routers
>>>>>
>>>>> Simon
>>>>>
>>>>> On Saturday, 26 November 2016 13:44:20 UTC+1, Wouter In t Velt wrote:
>>>>>
>>>>> Thank you for the explanation Erik! With the upgrade to 0.18 and the 
>>>>>> changes in navigation, I was wondering which route (pun intended) to 
>>>>>> follow 
>>>>>> with the upgrade. Not sure I follow completely though.
>>>>>>
>>>>>> In option 1, could you deal with redirect-like scenario's inside the 
>>>>>> SPA?
>>>>>> Like
>>>>>>
>>>>>>    1. user is on the "/apples" page, showing all available apples.
>>>>>>    2. user types "/apples/234"  in the url-bar
>>>>>>    3. there happens to be no such apple
>>>>>>    4. I want the user to stay on the "/apples" page, and get a 
>>>>>>    message like "this apple is forbidden fruit"
>>>>>>    5. at this point, I would want the url-bar to also say "/apples"
>>>>>>
>>>>>> Can this work with option 1? Or is this only possible with option 2?
>>>>>>
>>>>> ​
>>>>>
>>>> ​

-- 
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.

Reply via email to