dwyl / learn-elm-architecture-in-javascript

:unicorn: Learn how to build web apps using the Elm Architecture in "vanilla" JavaScript (step-by-step TDD tutorial)!
https://todomvc-app.herokuapp.com
GNU General Public License v2.0
213 stars 19 forks source link

Rudimentary Routing in a Client-side Web Application: Why? What? How? #46

Closed nelsonic closed 6 years ago

nelsonic commented 6 years ago

Routing in Web Application is surprisingly simple. There are only a couple of functions we need to write but we want to achieve the following goals:

Acceptance Criteria

For: #44 "Elmish" Todo List Example

nelsonic commented 6 years ago
setTimeout(function () { // delay for 1 second then run:
  console.log('window.location.href:', window.location.href);
  var base = window.location.href.split('#')[0];
  var active = '#/active';
  console.log('Setting the window.location.href to:', base + active);
  window.location.href = base + active;
  console.log('window.location.href:', window.location.href, 'updated!');
  console.log('window.history.length:', window.history.length);
  window.history.pushState(null, 'Active', active);
  console.log('window.history.length:', window.history.length);
}, 1000)

image