If you are using "hash" navigation for a single page app on Github Org or User Pages, you may run into a URL problem.
Users who visit a url like
http://myorg.github.io/upcoming-events
will be sent to the github page for a repo like
[email protected]:myorg/upcoming-events.git
Ultimately you may want them to be sent to a page like
http://myorg.github.io/#/upcoming-events
You can create this upcoming-events
repository, and put this index.html
file in its gh-pages
branch. It will take the "path" component of the url, move it to the "hash" component of the url, and redirect the user to that page
// Create an anchor tag. It will be quite useful!
var anchor = document.createElement('a');
// Set the "href" attribute to the user's current URL
anchor.href = window.location.href;
// Move the "pathname" property to the "hash" property
// This will convert something like
// http://myserver.com/mypage
// to http://myserver.com/#/mypage
anchor.hash = anchor.pathname;
anchor.pathname = '';
// Redirect the user
window.location.href = anchor.href;