-
Notifications
You must be signed in to change notification settings - Fork 83
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
How do I navigate without using Link or a href #80
Comments
Use the navigable mixin [1] and call this.navigate in your click handler. As for falling back to a server request, you may be able to do that using a 404 handler, or by implementing your own router using the router mixin. [1] https://github.com/andreypopp/react-router-component/blob/master/lib/NavigatableMixin.js |
Is there an example for this because I tried that but didn't work for me |
To be more precise I get the following error: So I am sure I am missing something, but not sure what |
OK I was being stupid, I forgot the contextual setting meant that my sub routes needed to be /xyz instead of /abc/xyz the error could be better like route not found or something but it does work |
An other related question: I am in a context aware router and now I want to navigate one level up. When I just call this.navigate("/") it goes to the root of its context, how do I break out? |
AFAIK you don't, you need a reference to the parent router, and you navigate from there. |
Ah ok so I need to pass in the parent router via the props (or use callbacks down the chain again). I looked in the code and I saw that RouterMixin has getParentRouter but I needed more magic for that one as well |
I'm also stuck on this. What do I mix the NavigatableMixin into? The top level App? How do I pass the navigatable method to the page? I've tried adding the mixin to the App, but I get:
|
You don't mix the NavigatableMixin into anything in most cases; that's advanced usage for custom routers. Simply use |
I am sorry but there is a real use-case for better usage of this.navigate("route"), not all navigation are pure links, many (in our case most) need to validate whether or not you can navigate to a next step, and before navigating if should submit some data. So the Link component is not sufficient for this (at least I have found it to be lacking in these scenario's). When I am navigating within the same router context I mix the NavigatableMixin in the react components where I need to navigate from. This will enable you to use this.naviage("route") in any method, i.e. button onclick handler Now I find having to pass in the parent router to be able to navigate to routes outside the current context also rather cumbersome, because it means pretty much passing it in all underlying components. So I'll be looking to see if I can build this in in a nice way (like the NavigatableMixin) Other then this I am really happy with the output, I like to be able to specify a router for larger sub components of our system, much nicer then everything at the route of the app. |
I am not saying that there is no use case, I am saying that it is advanced usage of this library and in most cases you are on your own. I am very happy to review and accept any useful PRs as extensions to this component. As for passing the parent router into underlying components, there are a few ways I have seen developers combat this. First, if you don’t expect your application to be embedded in a page multiple times, you could do as Facebook sometimes does with their Flux implementation and simply attach your routers to singletons that can be Otherwise, you may have some luck with React’s experimental If you are building a Flux app you may also have some luck simply firing an action to the dispatcher that instructs it to grab the parent router and route the app at the root. On Sep 15, 2014, at 12:45 PM, Mark Nijhof [email protected] wrote:
|
Thanks for your suggestions! I was thinking about a PR for sure :) |
Hi, so this.navigate(../other_route') will call navigate('/other_route') on the higher level router |
Also verified that this works with link [Link href="../other_route"]Home[/Link] |
Curious what you think about my proposal for getting to a parent router |
I've isolated my issue with NavigableMixin. If I If I If I |
I will try to build a test case in a fork of react-quickstart. This will highlight whether the issue is in my code, or a real problem. |
I've spun this issue out into its own ticket, as it seems to be an issue with |
Looks like this is safe to close, please re-open or create a new issue if you still have outstanding problems. |
I am looking for a way to navigate to a new route without using a Link component or plain a href tag, but instead in an onClickHandler. How should I do this so that if a route is matched it will be triggered else a server request is made?
The text was updated successfully, but these errors were encountered: