Skip to content

.navigate(href) is broken when called without a callback #81

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

Closed
JoshSGman opened this issue Sep 15, 2014 · 4 comments
Closed

.navigate(href) is broken when called without a callback #81

JoshSGman opened this issue Sep 15, 2014 · 4 comments

Comments

@JoshSGman
Copy link

In the documentation, it states that you can navigate programmatically using the .navigate method on a reference to the router component instance. Unfortunately, the source code requires a second argument to be passed in the form a function yet it doesn't state this anywhere. If you don't pass any additional arguments, the setPath method breaks as it expects a "navigation" argument to be an object:

Environment.prototype.navigate = function navigate(path, navigation, cb) {
  if (typeof navigation === 'function' && cb === undefined) {
    cb = navigation;
    navigation = {};
  }
  return this.setPath(path, navigation, cb);
}

Environment.prototype.setPath = function(path, navigation, cb) {
  if (!navigation.isPopState) {
    if (navigation.replace) {
      this.replaceState(path, navigation);
    } else {
      this.pushState(path, navigation);
    }
  }
  this.path = path;
  this.notify(navigation, cb);
}
@STRML
Copy link
Owner

STRML commented Sep 16, 2014

@JoshSGman Are you calling navigate on the Environment directly? While this is definitely a bug that should be fixed, I am wondering how you are doing this. See these lines in RouterMixin that prevent this.

@STRML STRML closed this as completed in 1a9220c Sep 16, 2014
@STRML
Copy link
Owner

STRML commented Sep 16, 2014

Published fix as 0.20.3, but please let me know re: above.

@JoshSGman
Copy link
Author

@STRML Thanks! The way I did it was as I understood it to be specified in the docs on the site.

I attached a ref to the Link, and then called

 this.refs.linkRef.navigate('/path') 

It looks like this ended up calling navigate on the Environment directly - with that said this was my understanding of how to route programmatically via the docs:

"Alternatively, if you have a reference to a router component instance, you can call its .navigate(href) method to do a transition to a different location. You can acquire a reference to a router by using React's Refs mechanism."

I wasn't looking to create an entire custom routing component.

@STRML
Copy link
Owner

STRML commented Sep 16, 2014

Ah. What I take that to mean is a Router component (Locations) - not a Link component, although it appears that both work.

On Sep 16, 2014, at 10:38 AM, Joshua Goldberg [email protected] wrote:

@STRML Thanks! The way I did it was as I understood it to be specified in the docs on the site.

I attached a ref to the Link, and then called

this.refs.linkRef.navigate('/path')
It looks like this ended up calling navigate on the Environment directly - with that said this was my understanding of how to route programmatically via the docs:

"Alternatively, if you have a reference to a router component instance, you can call its .navigate(href) method to do a transition to a different location. You can acquire a reference to a router by using React's Refs mechanism."

I wasn't looking to create an entire custom routing component.


Reply to this email directly or view it on GitHub.

MarkNijhof pushed a commit to Frende/react-router-component that referenced this issue Sep 16, 2014
7rulnik added a commit to kupibilet-frontend/react-router-component that referenced this issue May 25, 2016
7rulnik added a commit to kupibilet-frontend/react-router-component that referenced this issue May 25, 2016
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