react-router-v4

React-router app deployed on different locations (subdirectories)

浪子不回头ぞ 提交于 2020-01-05 04:06:07
问题 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=

React router links in app broken after move to cloudfront + SSL

不打扰是莪最后的温柔 提交于 2020-01-04 03:51:29
问题 I have a react app, using react-router hosted in an S3 bucket, using Route53 as a DNS provider. The app worked fine with the Route53 config pointing to the S3 bucket. Since I want to use SSL, I created a Cloudfront distribution pointing to the bucket, with an SSL cert., and pointed the DNS to it. Since doing that, none of the links work, (example.com works, but example.com/foo does not). It just returns a NoSuchKey error. I know that this is incorrect, as the key is definitely there, and it

Route is not matched

限于喜欢 提交于 2020-01-03 05:49:13
问题 I can't figure out why this is not matching my route for the CompanyDetailContainer . The route for Interview container works fine <IndexRoute component={HomePageContainer} /> <Route component={InterviewContainer} name="interview" path="interviews/companies/:companyId" /> <Route component={CompanyDetailContainer} name="companydetail" path="interviews/companies/:companyId/details" /> so http://localhost:8080/interviews/companies/10 hits the interview route fine but http://localhost:8080

How preserve query string and hash fragment, in React-Router 4 <Switch><Redirect>?

前提是你 提交于 2020-01-02 09:55:37
问题 If you have a <Redirect> inside a <Route> , you'll get a location and can do: <Redirect search={props.location.search} hash={props.location.hash} ... . However, when directly inside a top level <Switch> , the <Redirect> doesn't have any props.location to access search and hash on. Is there no way to preserve the query string and hash fragment, in a <Redirect> directly after a top level <Switch> (no <Route> higher up in the tree)? Example: (Typescript) Router({}, Switch({}, Redirect({ path: '/

React router v4 use declarative Redirect without rendering the current component

懵懂的女人 提交于 2020-01-02 08:07:48
问题 I am using a similar code like this to redirect in my app after users logged in. The code looks like the following: import React, { Component } from 'react' import { Redirect } from 'react-router' export default class LoginForm extends Component { constructor () { super(); this.state = { fireRedirect: false } } submitForm = (e) => { e.preventDefault() //if login success this.setState({ fireRedirect: true }) } render () { const { from } = this.props.location.state || '/' const { fireRedirect }

React-Router v4 rendering wrong component but matching correctly

旧巷老猫 提交于 2020-01-01 18:53:51
问题 I've got a sidebar with two buttons, 'test' and 'about'. Test (rocket icon) is rendered at '/test', and About (home icon) is rendered at '/'. They're both located at the root of the app and are nested within a component. When I start at '/' and click the Link to="/test" it always loads the 'About' component, and when I check the props for the componentDidMount of 'About', the match object contains match data for "/test". Only when I refresh does it render the proper component, 'Test', again.

Redirect to third party url using react-router-dom

拟墨画扇 提交于 2019-12-30 13:38:05
问题 I'm very much aware of the react-router-dom I want to do a conditional rendering of the component. If use is not logged in redirect him to some third party URL for example, the below code looks neat and works fine <Route exact path="/home" render={() => ( isLoggedIn() ? ( <Redirect to="/front"/> ) : ( <Home /> ) )}/> Let's say in the above example if I want to redirect to https://www.google.com how can I do it? if I write <Redirect to="https://www.google.com"> it gives me error. How can I

React Router v4 Redirect not working

北城以北 提交于 2019-12-29 19:46:18
问题 I have a route which redirects after checking a condition like this <Route exact path="/" render={()=>( Store.isFirstTime ? <Redirect to="intro" /> : <Home state={Store}/>)}/> The url changes when the condition is true but the component is not mounted. The rest of the component code is as below. render() { return ( <div> ... <Route exact path="/" render={()=>( Store.isFirstTime ? <Redirect to="intro" /> : <Home state={Store} /> )} /> <Route path="/intro" render={()=>(<IntroWizard state={Store

react-router (v4) how to go back?

旧时模样 提交于 2019-12-28 05:30:14
问题 Trying to figure out how can I go back to the previous page. I am using [react-router-v4][1] This is the code I have configured in my first landing page: <Router> <div> <Link to="/"><div className="routerStyle"><Glyphicon glyph="home" /></div></Link> <Route exact path="/" component={Page1}/> <Route path="/Page2" component={Page2}/> <Route path="/Page3" component={Page3}/> </div> </Router> In order to forward to subsequent pages, I simply do: this.props.history.push('/Page2'); However, how can

How to make using of react-router-dom for routing in Reactjs?

家住魔仙堡 提交于 2019-12-24 20:23:37
问题 I have made 3 components 1)Navbar 2)Content 3)Pagination On home page I want to display all 3 components. I have made another component Matchinfo which should get displayed when we click on view stats button (see screenshot for more clarification) . In app.js how should I make use of Routes so that 3 components will get display on home page i.e localhost:3000/ and when I click on view stats button it should render component Matchinfo. In app.js : import React, { Component } from 'react';