Is there a configuration in Github Pages that allows you to redirect everything to index.html for a Single Page App?

后端 未结 6 775
甜味超标
甜味超标 2021-01-17 15:28

I\'m trying to post my SPA app that works fine locally but when I push it to Github Pages, the interior pages don\'t register if you navigate to them directly.

For

6条回答
  •  Happy的楠姐
    2021-01-17 16:04

    Add this code to your index.html and 404.html files:

      // if it's on index.html
      if (window.sessionStorage.path) {
      let path = window.sessionStorage.path; // gets the path saved on sessionStorage
      window.history.pushState(null, null, path); // push it on url
      window.sessionStorage.removeItem('path'); // removes from session
    
    } else { // if it's on 404.html (path doens't exist)
      let path = window.location.pathname; // get the path url
      window.sessionStorage.path = path; // saves on sessionStorage
      window.location.href = '/'; // go to index
    }
    

提交回复
热议问题