Comments (8)
If you have a reference to a router, you can just do router.navigate('/sessions/new')
. You can acquire a reference to a router via refs.
from react-router-component.
Does this mean I have to propagate this router throughout all components? Any workaround if I just have a global router?
from react-router-component.
Yes, you can mixin NaviagatableMixin
and use this.navigate(path)
method:
var Component = React.createClass({
mixins: [require('react-router-component/lib/NavigatableMixin')],
redirect: function() {
this.navigate('/sessions/new')
},
...
})
Component should be created inside one of route handlers. But even that requirement could be removed if you use routing environment directly. See how Link
component is implemented — https://github.com/andreypopp/react-router-component/blob/master/lib/Link.js#L64
from react-router-component.
Great, thanks for the clarifications.
from react-router-component.
@polmiro do you think we can close this issue?
from react-router-component.
Yes, I also realized you are working on QuerystringKeyEnvironment for 0.16.0. I think it's going to be exactly what I need 👍
from react-router-component.
@polmiro yeah, QuerystringKeyEnvironment is alrady there but undocumented and doesn't support server side rendering yet.
from react-router-component.
For anyone else looking to redirect, here's a gist of a simple component that I use: https://gist.github.com/saidimu/2758402f7916f4e35dee
// jshint unused:true
var React = require('react');
var NavigatableMixin = require('react-router-component').NavigatableMixin;
var Redirect = React.createClass({
mixins: [NavigatableMixin],
_redirect: function(url) {
this.navigate(url);
},
propTypes: {
url: React.PropTypes.string.isRequired,
},
componentDidMount: function() {
console.log('Redirecting to %s: ', this.props.url);
this._redirect(this.props.url);
},
render: function() {
return null;
}
});//Redirect
module.exports = Redirect;
from react-router-component.
Related Issues (20)
- Higher-Order Component HOT 3
- Examples that pass args to renderRouteHandler are out of date
- Programmatically navigate? HOT 3
- Unknown prop `hash`
- Anyone integrated with redux?
- custom Link component (HighlightedLink) in ES6? HOT 1
- Question: Should the router have a callback to filter variable values from routes? HOT 2
- Should Hash environment url-decode routes? HOT 1
- Getting new warnings in console HOT 1
- Pathname Environment, History API and a double click in the back button to go back? HOT 7
- Update for React 15.5 warnings HOT 2
- queries do not survive in contextual routes.
- CaptureClicks drops querystrings
- Warning: getDefaultProps HOT 5
- docs don't make it clear how to navigate programatically HOT 1
- React 16.0 Support HOT 1
- onBeforeNavigation is invoked late HOT 1
- Location always renders a div HOT 3
- componentWillReceiveProps warning HOT 1
- Documentation Site Application Error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-router-component.