This is a library for managing browser navigation yourself.
The core functionality is the ability to “navigate” to new URLs, changing the address bar of the broswer without the browser kicking off a request to your servers. Instead, you manage the changes yourself in Elm.
Modify the current URL. This will not add a new entry to the browser history. It just changes the one you are on right now.
Go back some number of pages. So back 1 goes back one page, and back 2
goes back two pages.
Note: You only manage the browser history that you created. Think of this library as letting you have access to a small part of the overall history. So if you go back farther than the history you own, you will just go back to some other website!
Go forward some number of pages. So forward 1 goes forward one page, and
forward 2 goes forward two pages. If there are no more pages in the future,
this will do nothing.
Note: You only manage the browser history that you created. Think of this library as letting you have access to a small part of the overall history. So if you go forward farther than the history you own, the user will end up on whatever website they visited next!
This function augments Html.App.program. The new things include:
Parser — Whenever this library changes the URL, the parser you
provide will run. This turns the raw URL string into useful data.
urlUpdate — Whenever the Parser produces new data, we need to
update our model in some way to react to the change. The urlUpdate function
handles this case. (It works exactly like the normal update function. Take
in a message, update the model.)
Note: The urlUpdate function is called every time the URL changes. This
includes things exposed by this library, like back and newUrl, as well as
whenever the user clicks the back or forward buttons of the browsers. If the
address changes, you should hear about it.
Works the same as the program function, but can handle flags. See
Html.App.programWithFlags for more information.
This library is primarily about treating the address bar as an input to
your program. A Parser helps you turn the string in the address bar into
data that is easier for your app to handle.
The makeParser function lets you parse the navigation state any way you
want.
Note: Check out the examples associated with this GitHub repo to see a
simple usage. See evancz/url-parser for a more complex example of
URL parsing. The approach used there makes it pretty easy to turn strings into
structured data, and I hope it will serve as a baseline for other URL parsing
libraries that folks make.
A bunch of information about the address bar.
Note: These fields correspond exactly with the fields of document.location
as described here.
Good luck with that.
Note 2: You should be using a library like evancz/url-parser to
deal with all this stuff, so generally speaking, you should not have to deal
with locations directly.
Step to a new URL. This will add a new entry to the browser history.
Note: If the user has gone
backa few pages, there will be “future pages” that the user can goforwardto. Adding a new URL in that scenario will clear out any future pages. It is like going back in time and making a different choice.