routing.html 910 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <script src="../bower_components/page/page.js"></script>
  2. <script>
  3. window.addEventListener('WebComponentsReady', function() {
  4. // We use Page.js for routing. This is a Micro
  5. // client-side router inspired by the Express router
  6. // More info: https://visionmedia.github.io/page.js/
  7. // Removes end / from app.baseUrl which page.base requires for production
  8. if (window.location.port === '') { // if production
  9. page.base(app.baseUrl.replace(/\/$/, ''));
  10. }
  11. page('/', function() {
  12. app.route = 'home';
  13. });
  14. page(app.baseUrl, function() {
  15. app.route = 'home';
  16. });
  17. // 404
  18. page('*', function() {
  19. app.$.toast.text = 'Can\'t find: ' + window.location.href + '. Redirected you to Home Page';
  20. app.$.toast.show();
  21. page.redirect(app.baseUrl);
  22. });
  23. // add #! before urls
  24. page({
  25. hashbang: true
  26. });
  27. });
  28. </script>