Search code examples
javascriptjqueryhtmlhtml5-history

HTML5 History API not working after refreshing the URL


I'm building very simple SPA 'wannabe' site /for a friend and for exercise/. The idea is simple - 3 static pages: home, portfolio, contact. I've made the links from the portfolio and contact to change the url and I just need to make some functions to change the content. So far so good, but when I refresh the page when I'm on /contact or /portfolio "page" i get error "Cannot GET /portfolio". Same happens when I try to copy and paste the link in other browser. The purpose of the site is to be able to send links and open em. Could this be achieved without server-side?


Solution

  • No.

    You must change have a server-side, because this mode requires URL rewriting. You have to rewrite all your requests to the index of your app.

    You can disable HTML5 location mode (and use hash instead).