erikringsmuth / app-router

Router for Web Components
https://erikringsmuth.github.io/app-router/
MIT License
611 stars 83 forks source link

Add refresch to options in go method #56

Closed PedroHurtado closed 9 years ago

PedroHurtado commented 9 years ago

refresch options passed in value to true when we call the method go. In a scenario with a global filter for example to traslate not refresh the page and global filter not work. This involves the following changes in the method go

Chages in AppRouter.go

AppRouter.go = function(path, options) { if (this.getAttribute('mode') !== 'pushstate') { // mode = auto or hash path = '#' + path; } if (options && options.replace !== true) { window.history.pushState(null, null, path); } else { window.history.replaceState(null, null, path); } stateChange(this,options && options.refresch); };

Changes in stateChange

// Find the first that matches the current URL and change the active route function stateChange(router,refresch) { var url = utilities.parseUrl(window.location.href, router.getAttribute('mode'));

// don't load a new route if only the hash fragment changed

if (!refresch && url.path === previousUrl.path && url.search === previousUrl.search && url.isHashPath === previousUrl.isHashPath) {
  scrollToHash(url.hash);
  return;
}
previousUrl = url;

// fire a state-change event on the app-router and return early if the user called event.preventDefault()
var eventDetail = {
  path: url.path
};
if (!fire('state-change', eventDetail, router)) {
  return;
}

// find the first matching route
var route = router.firstElementChild;
while (route) {
  if (route.tagName === 'APP-ROUTE' && utilities.testRoute(route.getAttribute('path'), url.path, router.getAttribute('trailingSlash'), route.hasAttribute('regex'))) {
    activateRoute(router, route, url);
    return;
  }
  route = route.nextSibling;
}

fire('not-found', eventDetail, router);

}

This allows call the method go as follows go ('/', {refresch: true}) and thus to make the cycle is complete page

erikringsmuth commented 9 years ago

I think this is the same as a bug that was found yesterday in issue https://github.com/erikringsmuth/app-router/issues/51, PR https://github.com/erikringsmuth/app-router/pull/52. Try pulling version 2.3.1 and see if that fixes it.

erikringsmuth commented 9 years ago

I also realized there's another bug with this line. https://github.com/erikringsmuth/app-router/blob/master/src/app-router.js#L145

It needs an additional check at the end.

&& url.hash !== previousUrl.hash

I think this is what you're seeing.

erikringsmuth commented 9 years ago

I fixed this and pushed version 2.3.2 https://github.com/erikringsmuth/app-router/commit/1bd2d50d2b51c0c5f87d70c203aa5a8295929aac. It will refresh by default now.

PedroHurtado commented 9 years ago

thanks;)