Skip to content
This repository has been archived by the owner on Oct 5, 2019. It is now read-only.

How to trigger route change with javascript code #13

Closed
leapon opened this issue Dec 8, 2016 · 5 comments
Closed

How to trigger route change with javascript code #13

leapon opened this issue Dec 8, 2016 · 5 comments

Comments

@leapon
Copy link

leapon commented Dec 8, 2016

In the kitchensink example, route changes are achived with link attribute or "back" class name.

For example:

How can I force a route change using javascript code?

I searched source code and saw this.$emit to trigger event. However I can't find where these events are received and route gets changed in Framework7-Vue code base.

@leapon leapon changed the title How to trigger route code with javascript code How to trigger route change with javascript code Dec 8, 2016
@leapon leapon mentioned this issue Dec 8, 2016
@damir
Copy link

damir commented Dec 8, 2016

Each F7View component has a router under f7View.router property.

You can access it from your main component with $children[0].$children[0].f7View.router and then save it somewhere with friendlier name.

@leapon
Copy link
Author

leapon commented Dec 9, 2016

@damir Thanks! that works!

goNext: function(event) {
  console.log('go to page2');
  var f7View = this.$root.$children[0].$children[0].$children[0].f7View;
  console.log('>>> f7View:', f7View);
  f7View.loadPage('/page2/');
}

@chasebank
Copy link

That does indeed seem to work, but can someone explain the logic behind the long string of children? What exactly are those pointing to? I would expect root > app(child) > views(child) > f7view, but that'd be two children, which is incorrect.

@bencompton
Copy link
Member

Yeah, that certainly is not the most intuitive way to access views / the router. As of this PR, it is now possible to do something like this instead:

this.$f7['mainView'].loadPage('/page2/')

@chasebank
Copy link

Ah, thanks. That's much better!

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

No branches or pull requests

4 participants