react-router-redux

How to use react-router-redux routeActions?

痴心易碎 提交于 2019-12-03 00:30:34
I'm trying to modify the example code of react-router-redux. https://github.com/rackt/react-router-redux/blob/master/examples/basic/components/Home.js this is my Home.js class Home extends Component { onSubmit(props) { this.props.routeActions.push('/foo'); } } I also have a mapDispatchToProps for it. function mapDispatchToProps(dispatch){ return bindActionCreators({ routeActions },dispatch); } When i called onSubmit function, I got an error Uncaught TypeError: this.props.routeActions.push is not a function If i remove this.props in onSubmit, the key in the URL changed but its still on the same

为什么要用react-router-redux

匿名 (未验证) 提交于 2019-12-03 00:22:01
react-router-redux 将react-router 和 redux 集成到一起,用redux的方式去操作react-router。例如,react-router 中跳转需要调用 router.push(path),集成了react-router-redux 就可以通过dispatch的方式使用router,例如跳转可以这样做 store.dispatch(push(url))。本质上,是把react-router自己维护的状态,例如location、history、path等等,也交给redux管理。一般情况下,是没有必要使用这个库的。 文章来源: 为什么要用react-router-redux

onEnter Transitions with React Router and Redux Simple Router Dont Render New Route's Component

♀尐吖头ヾ 提交于 2019-12-02 18:37:21
I have an app using react @0.14, redux @3.05, react-router @1.0.3, and redux-simple-router @2.0.2. I'm trying to configure onEnter transitions for some of my routes based on store state. The transition hooks successfully fire and push new state to my store, which changes the url. However, the actual component that is rendered on the page is the original component handler from the route match, not the new component handler for the new url. Here is what my routes.js file looks like export default function configRoutes(store) { const authTransition = function authTransition(location, replaceWith)

react-router: how to get the previous route in onEnter handler?

放肆的年华 提交于 2019-12-02 03:47:50
问题 I'm trying to find a way to read the previous route/path when a user hits a new one, within the onEnter handler. I have a React Router structured like so: <Router history={history}> <div className="index"> <Route path="/" component={ComposedAppComponent} onEnter={this.onEnterHandler.bind(this)} > <Route name="streamKey" path=":streamKey"> <Route name="articleUri" path="(**)" /> </Route> </Route> </div> </Router> the function, onEnterHandler , looks like so: onEnterHandler(nextRouteState) {

react-router: how to get the previous route in onEnter handler?

廉价感情. 提交于 2019-12-02 02:24:42
I'm trying to find a way to read the previous route/path when a user hits a new one, within the onEnter handler. I have a React Router structured like so: <Router history={history}> <div className="index"> <Route path="/" component={ComposedAppComponent} onEnter={this.onEnterHandler.bind(this)} > <Route name="streamKey" path=":streamKey"> <Route name="articleUri" path="(**)" /> </Route> </Route> </div> </Router> the function, onEnterHandler , looks like so: onEnterHandler(nextRouteState) { const { streamKey, splat } = nextRouteState.params; const nextPath = `/${streamKey}/${splat}`; const

Routes are not navigating when React v15.5 setup with react-redux v5 is

核能气质少年 提交于 2019-12-01 06:43:49
I am new with React and I have setup my React project with Facebook's create-react-app . Here are the core files: Index.js import React from 'react'; import ReactDOM, { render } from 'react-dom'; import { BrowserRouter as Router } from 'react-router-dom'; import createHistory from 'history/createBrowserHistory'; import { createStore, applyMiddleware } from "redux"; import { Provider } from 'react-redux' import { routerMiddleware, syncHistoryWithStore } from 'react-router-redux'; import thunk from 'redux-thunk'; import reducers from './reducers'; import App from './containers/App'; import

React Router: Cannot read property 'pathname' of undefined

♀尐吖头ヾ 提交于 2019-12-01 02:15:06
I've just started learning React and got stuck at this error. Uncaught TypeError: Cannot read property 'pathname' of undefined at new Router Here is my code: var React = require('react'); var ReactDOM = require('react-dom'); var { Route, Router, IndexRoute } = require('react-router'); var hashHistory = require('react-router-redux') var Main = require('./components/Main'); ReactDOM.render( <Router history={hashHistory}> <Route path="/" component={Main}> </Route> </Router>, document.getElementById('app') ); The tutorial I was following uses React-Router 2.0.0, but on my desktop I'm using 4.1.1.

React Router 4.x - PrivateRoute not working after connecting to Redux

断了今生、忘了曾经 提交于 2019-11-30 11:36:00
问题 PrivateRoute available in Example https://reacttraining.com/react-router/web/example/auth-workflow is not working after connecting with Redux. My PrivateRoute look almost same to the original version but only connected to Redux and used it instead of fakeAuth in the original example. const PrivateRoute = ({ component: Component, auth, ...rest }) => ( <Route {...rest} render={props => auth.isAuthenticated ? <Component {...props} /> : <Redirect to={{ pathname: "/login" }} />} /> ); PrivateRoute

How to sync Redux state and url query params

人盡茶涼 提交于 2019-11-30 10:53:42
问题 I have a web page with a search panel. Search panel has several input fields: id, size, ... What I want is when user set search values (for example: id=123 and size=45) and press a search button: searchState in Redux reducer should be updated with new search values (id=123 and size=45) URL should be changed to "http://mydomain/home?id=123&size=45" And on the other hand if the user changes URL to http://mydomain/home?id=111&size=22 then: searchState in reducer should be changed with new search

How to dispatch Redux action from stateless component when route is loaded?

拥有回忆 提交于 2019-11-30 08:10:26
Goal : when loading a react-router route, dispatch a Redux action requesting asynchronic Saga worker to fetch data for the underlying stateless component of that route. Problem : stateless components are mere functions and don't have lifecycle methods, such as componentDidMount, so I can't(?) dispatch Redux action from inside the function. My question is partly related to Converting stateful React component to stateless functional component: How to implement "componentDidMount" kind of functionality? , but my goal is to merely dispatch a single Redux action requesting data to be populated to