A SPA boiler plate for elm projects
Elm - for sweet 🍬 functional code
Tachyons - for speedy 💨 modular styling
src/ -- contains elm code
src/Routes/ -- contains Html Msgs for your pages && elements
public/ -- contains built code, and an index.html file
npm run dev -- will start watching your elm project, and run a local dev server
npm run build -- will build your elm project as a js file, ready to serve as a static site
Routing is done via a #url to avoid reloading the page and loosing model's state. There are workarounds for this, but this a simple solution that requires minimal code (check resources below for alternatives). The router works by using the Navigation
package which gives us access to the url. Our app checks the current url address, updates this route in the modal
, then renders the page according to the modal.route
.
All routing takes place in the State.elm
& View.elm
files:
getRoute
inUpdate.elm
acts as a virtual router, which gets the current url and sets it in model- the
case
statement inView.elm
acts as a handler which serves the correctHtml Msg
To add a new route you need to:
- Add a your route as a msg type in Route in
Type.elm
- Create and export a
Html Msg
for the new page and place it in a separate file inRoutes/
- Add a
case
for the route undergetRoute
inState.elm
- Serve the file by adding a
case
for the importedHtml Msg
inview
To duplicate this repo for your own use follow these gitHub instructions. And don't forget to ⭐ 🌟 ⭐ to say thanks!
This is a basic way of routing a SPA using this tutorial
Further reading on best practises and limitations can be found here: Choosing Elm SPA architecture