react-router-v4

Pass props through a higher order component from a Route

杀马特。学长 韩版系。学妹 提交于 2019-12-04 02:08:08
I have a problem with my Higher Order Component. I am trying to pass props from a <Layout /> component down a route (React Router v4). The components specified in the routes are wrapped by a HOC, but the props that I pass never reaches the component. Also, I can't use the HOC without using export default () => MyHOC(MyComponent) . I can't figure out why, but that might have something to do with it? Layout.js const Layout = ({ location, initialData, routeData, authenticateUser }) => ( <Wrapper> <Container> <Switch> // how do I get these props passed through the HOC? render instead of component

How to use react-router 4.0 to refresh current route? not reload the whole page

杀马特。学长 韩版系。学妹 提交于 2019-12-04 01:13:06
'react-router-dom' has refresh function here , but I don't know how to call this method, also their well formatted document doesn't bother to explain this. window.location.reload() doesn't work for me, because it wipes out the app store as well. I changed some data, and then need to reload the route with updated data. I also read this: https://github.com/ReactTraining/react-router/issues/1982 https://github.com/ReactTraining/react-router/issues/2243 this thread is exactly discussing my question: https://github.com/ReactTraining/react-router/issues/4056 and still clueless how to do it. This

React Router v4 routes not working

帅比萌擦擦* 提交于 2019-12-04 00:46:56
I am relatively new to reacts and I'm trying to figure out how to get React router to work. I've got a super simple test app that looks like this: import React from 'react'; import ReactDOM from 'react-dom'; import {BrowserRouter as Router, Route, Switch, IndexRoute, Link} from 'react-router-dom'; const Home = () => <h1><Link to= "/about">Click Me</Link></h1> const About = () => <h1>About Us</h1> const Test = () => ( <Router> <Switch> <Route path ="/" component = {Home} /> <Route path ="/about" component = {About} /> </Switch> </Router> ) ReactDOM.render(<Test />, document.getElementById('app'

React Router with React 16.6 Suspense “Invalid prop `component` of type `object` supplied to `Route`, expected `function`.”

十年热恋 提交于 2019-12-03 16:26:53
问题 I'm using the latest version (16.6) of React with react-router (4.3.1) and trying to use code splitting using React.Suspense . Although my routing is working and the code did split into several bundles loaded dynamically, I'm getting a warning about not returning a function, but an object to Route . My code: import React, { lazy, Suspense } from 'react'; import { Switch, Route, withRouter } from 'react-router-dom'; import Loading from 'common/Loading'; const Prime = lazy(() => import('modules

How to get params in component in react router dom v4?

别等时光非礼了梦想. 提交于 2019-12-03 14:02:53
问题 I have this code: <BrowserRouter> <Route path="/(:filter)?" component={App} /> </BrowserRouter> the filter param or '' on the root is suppose to be on App components' props base on the previous react router versions? This is my code on my App: const App = ({params}) => { return ( // destructure params on props <div> <AddTodo /> <VisibleTodoList filter={params.filter || 'all'} // i want to git filter param or assign 'all' on root /> <Footer /> </div> ); } I logged this.props.match.params on

Does order in which you wrap component with connect and withRouter matter

谁说胖子不能爱 提交于 2019-12-03 12:29:15
Which HOC will wrap the other. Does the order of wrapping with multiple HOCs matter in react or not? I have created multiple HOCs withSocket , withLoadingBar etc etc. Should I be worry about deep ugly nesting, Will it make an impact on performance of component? Does the order of wrapping with multiple HOCs matter in react or not? The order in which you wrap the HOCs matters because of the props that are passed on from one HOC to its child component. Consider the following example const mapStateToProps(state, props) { console.log(props.match); return { match: props.match } } First case:

Authenticate async with react-router-v4

眉间皱痕 提交于 2019-12-03 12:18:10
问题 I have this PrivateRoute component (from the docs): const PrivateRoute = ({ component: Component, ...rest }) => ( <Route {...rest} render={props => ( isAuthenticated ? ( <Component {...props}/> ) : ( <Redirect to={{ pathname: '/login', state: { from: props.location } }}/> ) )}/> ) I would like to change isAuthenticated to an aysnc request isAuthenticated() . However, before the response has returned the page redirects. To clarify, the isAuthenticated function is already set up. How can I wait

React router 4 history.listen never fires

左心房为你撑大大i 提交于 2019-12-03 11:22:38
Switched to router v4 and history v4.5.1 and now history listener not working import createBrowserHistory from 'history/createBrowserHistory' const history = createBrowserHistory() history.listen((location, action) => { console.log(action, location.pathname, location.state) // <=== Never happens }) render( <Provider store={store}> <Router history={history}> ... </Router> </Provider>, document.getElementById('root') ) Any ideas why it is being ignored? Since you are using BrowserRouter(with import alias Router as mentioned in comments of the question), it doesn't care the history prop you pass

Material-UI's Tabs integration with react router 4?

浪子不回头ぞ 提交于 2019-12-03 10:37:22
问题 The new react rotuer syntax uses the Link component to move around the routes. But how could this be integrated with materiaul-ui ? In my case, I'm using tabs as the main navigation system, So in theory I should have something like this: const TabLink = ({ onClick, href, isActive, label }) => <Tab label={label} onActive={onClick} /> export default class NavBar extends React.Component { render () { return ( <Tabs> <Link to="/">{params => <TabLink label="Home" {...params}/>}</Link> <Link to="

how to use react-native-web and react-navigation together and access from web url

若如初见. 提交于 2019-12-03 09:59:47
UPDATE : react-navigation web support is done. follow this: https://reactnavigation.org/docs/en/web-support.html ORIGIN : I try to share my code between react-native and web. when I try react-native-web, it works well. but there is only one question, how to access the specific screen from URL? I read the react-navigation docs, there nothing about that. and react-router-native can catch the web URL, but it has navigator likes StackNavigator/DrawerNavigator. and idea about that? 来源: https://stackoverflow.com/questions/49186634/how-to-use-react-native-web-and-react-navigation-together-and-access