Question

I am trying to change

http://domain.co.uk/#!/pagename

to

http://domain.co.uk/pagename

I was thinking of going URL re-write and then realised that as it is a single page website this will not work, so I am stuck!

Is there a way to do it given existing code-base (a quick javascript function?) or is it just something I have to live with?

! am guessing the latter (well could change to domain.co.uk#pagename I suppose) but am happy to be proved wrong!

Was it helpful?

Solution

The basics are simple enough:

if (location.hash && (location.hash.substr(1,1) === "!")) {
    location.replace(location.toString().replace('#!', "/"));
};

You just need to make sure that the new URLs work first.

That means:

  1. Updating the client side code to use pushState and friends (so you stop generating hashbang URIs)
  2. Updating the server side code so it can deliver each page of the site in the correct state without depending on the client side code (so that (a) any page can load quickly and efficiently and (b) JavaScript becomes a performance boosting bonus instead of a search engine hating dependancy)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top