Files
polymer-starter-kit/app/elements/routing.html
Chuck Horton 7082366bc2 Add Github Pages deploy and routing
This does the following:

1. Add gulp tasks to deploy to Github Pages
2. Revises routing to handle hosting from a subfolder
3. Allows development environment to run from root while production can
run from subfolder
4. Add link to PSK demo in readme.md
5. Add deploy section to readme.md
6. Add detail Deploy to Github Pages recipe

Remove getUrl function and use data binding instead

With Polymer 1.2.0 we can now use compound bindings so getUrl function
is not needed.

Change Github to GitHub

Fixed linting errors

Add example for deploy to GitHub pages

use $ variable instead of require for ghPages
2015-11-12 10:10:22 -08:00

65 lines
1.8 KiB
HTML

<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<script src="../bower_components/page/page.js"></script>
<script>
window.addEventListener('WebComponentsReady', function() {
// We use Page.js for routing. This is a Micro
// client-side router inspired by the Express router
// More info: https://visionmedia.github.io/page.js/
// Removes end / from app.baseUrl which page.base requires for production
if (window.location.port === '') { // if production
page.base(app.baseUrl.replace(/\/$/, ''));
}
// Middleware
function scrollToTop(ctx, next) {
app.scrollPageToTop();
next();
}
// Routes
page('/', scrollToTop, function() {
app.route = 'home';
});
page(app.baseUrl, scrollToTop, function() {
app.route = 'home';
});
page('/users', scrollToTop, function() {
app.route = 'users';
});
page('/users/:name', scrollToTop, function(data) {
app.route = 'user-info';
app.params = data.params;
});
page('/contact', scrollToTop, function() {
app.route = 'contact';
});
page('*', function() {
app.$.toast.text = 'Can\'t find: ' + window.location.href + '. Redirected you to Home Page';
app.$.toast.show();
page.redirect(app.baseUrl);
});
// add #! before urls
page({
hashbang: true
});
});
</script>