Skip to content

raulra08/raulra08.github.io

 
 

Repository files navigation

Basic instructions - there are two things you need from this repo for your single page app to run on GitHub Pages.

  1. Copy over the [404.html][404html] file to your repo as is
    • Note that if you are setting up a Project Pages site and not using a [custom domain][customdomain] (i.e. your site's address is username.github.io/repo-name), then you need to set [pathSegmentsToKeep to 1 in the 404.html file][pathsegmentstokeep] in order to keep /repo-name in the path after the redirect. If you are using React Router you'll need to tell it to use the repo-name as the basename, for example <BrowserRouter basename="/repo-name" />.
  2. Copy the [redirect script][indexhtmlscript] in the index.html file and add it to your index.html file - Note that the redirect script must be placed before your single page app script in your index.html file.  
<script type="text/javascript"> // Single Page Apps for GitHub Pages // MIT License // https://github.com/rafgraph/spa-github-pages // This script checks to see if a redirect is present in the query string, // converts it back into the correct url and adds it to the // browser's history using window.history.replaceState(...), // which won't cause the browser to attempt to load the new url. // When the single page app is loaded further down in this file, // the correct url will be waiting in the browser's history for // the single page app to route accordingly. (function(l) { if (l.search[1] === '/' ) { var decoded = l.search.slice(1).split('&').map(function(s) { return s.replace(/~and~/g, '&') }).join('?'); window.history.replaceState(null, null, l.pathname.slice(0, -1) + decoded + l.hash ); } }(window.location)) </script>

Packages

No packages published

Languages

  • HTML 100.0%