react-router-v4

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

自闭症网瘾萝莉.ら 提交于 2020-01-21 04:14:07
问题 '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

Passing custom props to router component in react-router v4

有些话、适合烂在心里 提交于 2020-01-18 02:21:09
问题 I'm using React Router to create a multi page app. My main component is <App/> and it renders all of the routing to to child components. I'm trying to pass props via the route, and based on some research I did, the most common way for child components to tap into props passed down is via the this.props.route object that they inherit. However, this object is undefined for me. On my render() function in the child component, I console.log(this.props) and am return an object that looks like this

Reactjs why useEffect sometimes runs on every mount/render instead of just first

烈酒焚心 提交于 2020-01-16 09:06:09
问题 I have a useEffect in my Routes in App.js <Switch> <Route exact path={['/en', '/fr']} component={HomePage} /> <Route path={['/en/*', '/fr/*']}> <Route path="/:lang/*" component={DefaultLanguage} /> in the same file(App.js) we have the component like so (using react-localize-redux): const DefaultLanguage = withLocalize( ({ activeLanguage, setActiveLanguage, ...props }) => { useEffect(() => { console.log('setting active language'); setActiveLanguage(props.match.params.lang); }, []); return <></

React Router v4 Redirect fails to redirect

谁说胖子不能爱 提交于 2020-01-14 06:08:06
问题 With onEnter replaced with render I changed my code to match the router v4 specs. The point was to prevent the /signup page from getting displayed when logged in.What do i miss in my code? import React from 'react'; import ReactDOM from 'react-dom'; import {Meteor} from 'meteor/meteor'; import {BrowserRouter, Route, Redirect, Switch} from 'react-router-dom'; import browserHistory from 'history'; import {Tracker} from 'meteor/tracker'; import Signup from '../imports/ui/Signup'; import MyLink

React Router v4 routes not working

♀尐吖头ヾ 提交于 2020-01-12 12:54:26
问题 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 ="

React Router v4 routes not working

送分小仙女□ 提交于 2020-01-12 12:54:22
问题 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 ="

API call after reloading same route via react router

时光怂恿深爱的人放手 提交于 2020-01-10 03:15:39
问题 I am reloading a Component via Redirect from react-router-dom v4, When the Component loads for the first time the api calls occur within ComponentDidMount. But this method doesn't run when component reload is triggered by Redirect. I have the component TopicList , which is displayed by the path /topic using Route from react-router-dom PostTopic is a Modal that is rendered within TopicList. Inside PostTopic , i add a property called redirect, to the state, and use this to render a Redirect

Simple Conditional Routing in Reactjs

风流意气都作罢 提交于 2020-01-09 04:25:09
问题 How to make conditional Routing, if and only if some conditions satisfies then only routing should happen. for example, if and only if the user enters the correct credentials login should be successful and the user should be able to see the welcome page. if we hit directly some URL like 'localhost:8080/welcome' that should not be navigated to welcome page, only after login welcome page should be seen. how can I achieve this, can anyone help me please..thank you. App.js import React, {

React Router - Uncaught SyntaxError: Unexpected token < when refreshing an URL with params

混江龙づ霸主 提交于 2020-01-06 05:26:06
问题 I am using react 16 and react router 4 , webpack and webpack dev server . I do have the following Route : <Route path="/company/:symbol" render={this.getCompanyPageRoute} /> And I do navigate to this route through the following: this.props.history.push('/company/blablabla'); Everything works fine. But if I refresh the page with this URL, I get the following error: Uncaught SyntaxError: Unexpected token < I've seen that there are several posts of this error, but I was not albe to fix the issue

React-router app deployed on different locations (subdirectories)

喜欢而已 提交于 2020-01-05 04:07:21
问题 I have a react-router app that I have to deploy on different locations (subdirectories), so the basename would change. For example it should have the following paths: / (production) /appname/env1 /appname/env2 I want to use Browser History, so I implemented the BrowserRouter from react-router, but I cannot pass to it a static basename. And obviously the routing won't work, for example if I don't pass any basename to BrowserRouter , if my homepage route is: <Route path="/" exact component=