Skip to content

Instantly share code, notes, and snippets.

@Opus1no2
Created August 28, 2014 19:54
Show Gist options
  • Save Opus1no2/6f71d90ba330ca6a6833 to your computer and use it in GitHub Desktop.
Save Opus1no2/6f71d90ba330ca6a6833 to your computer and use it in GitHub Desktop.
var pathRay = window.location.pathname.split('/');
// Make sure that split returns
// an array of at least 2 values
// the value we want will be the 2nd value
if (pathRay.length >= 2) {
var firstRoute = pathRay[1];
}
// Make sure the second value
// is not an empty string
if (firstRoute.length > 0) {
// Now we know for sure that the
// window location contains a non empty
// value such as http://foo.com/bar
// where 'bar' is the value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment