Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture any URL change #77

Open
amatiasq opened this issue May 28, 2014 · 6 comments
Open

Capture any URL change #77

amatiasq opened this issue May 28, 2014 · 6 comments

Comments

@amatiasq
Copy link

Hey there, I need some way to capture any type of URL change, is there a way to do this? Something like

Path.onNavigate(function(route) {
  model.data = {};
});
@nits
Copy link

nits commented Sep 15, 2015

Did you find solution for this?

@amatiasq
Copy link
Author

No, I moved to another library.

@nits
Copy link

nits commented Sep 15, 2015

Which library?

@amatiasq
Copy link
Author

Sorry I don't remember, it's more than one year ago.

@nits
Copy link

nits commented Sep 20, 2015

Ok. Path.rescue did the work for me. Thanks anyways.

@ghost
Copy link

ghost commented May 23, 2016

@amatiasq The way I do it in pure JS is:

var routeFunc = function() {
  var page = document.location.hash.split('=');
  switch (page[0]) {
    case '#!archive':
      // some code
      break;
    case '#!home':
      // some code
      break;
    default:
      // some code
  }
};

var initFunc = function() {
  routeFunc();
  window.addEventListener('hashchange', routeFunc, false);
};
window.addEventListener('load', initFunc, false);

You'll have to prefix all urls with #! like in the following example: #!post=test_page

I'm using the same code in my blog - https://github.com/wifiextender/wifiextender.github.io/blob/master/dev/src/main.js#L105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants