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

Apply current route at the start #6

Open
ivan-kleshnin opened this issue Sep 3, 2015 · 1 comment
Open

Apply current route at the start #6

ivan-kleshnin opened this issue Sep 3, 2015 · 1 comment

Comments

@ivan-kleshnin
Copy link
Contributor

Direct browser access to /about results in defaultRoute applied.
Only JS navigation works.

So router basically is not aware that it's alredy "other" page and navigation event had to be sent...

Following http://router5.github.io/docs/api-reference.html
It seems that startPathOrState from router5.start([startPathOrState], [done])
should be used.

However

function main({DOM, router}) {
  ...
  return {
    DOM: vtree$,
    router: Observable.from([["start", window.location.pathname + "?" + window.location.search]])
  }
}

seems to has no effect.

I can surely debug this but maybe you'll answer quicker.

@ivan-kleshnin ivan-kleshnin changed the title Apply current url to route Apply current route at the start Sep 3, 2015
@axefrog
Copy link
Owner

axefrog commented Sep 3, 2015

I had this problem also; I had to use startWith to issue an initial event. This is router5's behaviour, but I might flag this as something to add in myself. I'm in the middle of completely rewriting the driver to properly support router5 features and to allow for scoping support (as per cycle/core issue 167).

Here's what I'm exposing in my own code in my router.js file:

function getRouterActions(router) {
  return {
    route$: router.addListener()
      .startWith({ toState: router.matchPath(location.pathname) })
      .map(change => {
        log.trace(`Route changed to ${change.toState.name}`);
        return {
          name: change.toState.name,
        };
      }),
    router$: Rx.Observable.just('start').delay(100)
  };
}

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

No branches or pull requests

2 participants