react-router

Call a method passed as a prop in react

a 夏天 提交于 2021-02-20 19:10:12
问题 i have method in my parent element, an d i passed it as a prop; like this: <NavBar retrieveList={this.retrieveList}/> and in my child component i can not able to call this method from another method body. handleCloseModal () { window.$('#newHireModal').modal('hide'); /* this is working */ console.log(this.props.retrieveList); /* it gives method body, just to be sure props is coming here */ this.props.retrieveList; /*it gives "Expected an assignment or function call..." */ this.props

browserHistory.push not working in react

自闭症网瘾萝莉.ら 提交于 2021-02-20 02:59:05
问题 I am very new to reactJs. I am trying to change the tab on click of button. For this I am using browserHistory . Problem here is url is getting changed but component is not getting rendered. Couldn't understand this. browserHistory.push("/personalInfo"); This is how I am trying to change the tab. Url is getting changed to http://localhost:3000/personalInfo . But component is not rendered, when I refresh the browser, it's getting changed. 回答1: Use withRouter import React, { Component } from

How to change header background color in react based on location

社会主义新天地 提交于 2021-02-19 15:51:16
问题 How do I change my headers color based on what route/page I am on in my React project? I have looked at withRouter but I am not sure how to use the example. I just want to do something like if the route is not the Home component then change the background color of the header to blue. Seems like it would be simple but can't figure it out. 回答1: You can use the location prop that is added to your component by connecting the component to the router via withRouter . From there you apply a

How to change header background color in react based on location

让人想犯罪 __ 提交于 2021-02-19 15:50:13
问题 How do I change my headers color based on what route/page I am on in my React project? I have looked at withRouter but I am not sure how to use the example. I just want to do something like if the route is not the Home component then change the background color of the header to blue. Seems like it would be simple but can't figure it out. 回答1: You can use the location prop that is added to your component by connecting the component to the router via withRouter . From there you apply a

React Router display one component for all routes ( a header)

浪尽此生 提交于 2021-02-19 05:43:05
问题 Have a question regarding react router. I have a header item that I would like to display for all routes. And of course, I want this to be part of the so that the user can click items from a nav. Currently I have my <Header /> outside of my <Router> and I guess this isn´t working since my router then don't know to re-render? import { BrowserRouter as Router, Route, Switch } from 'react-router-dom' <div> <Header /> <Router> <Switch> <Route exact path="/" component={Posts} /> <Route exact path=

Bootstrap select element not rendered with react-router

邮差的信 提交于 2021-02-19 00:57:11
问题 I am making a basic app in reactjs. I've setup routes for 3 components. The problem is select fields don't appear when the component is rendered. I'm using bootstrap-select library for the select fields. The select fields that have className as "selectpicker" do not render, they just aren't there. They showed up when I removed "selectpicker" from the className. When using "selectpicker", they show up when the browser page is reloaded. Below is a snippet from my code: https://codesandbox.io/s

Bootstrap select element not rendered with react-router

柔情痞子 提交于 2021-02-19 00:56:17
问题 I am making a basic app in reactjs. I've setup routes for 3 components. The problem is select fields don't appear when the component is rendered. I'm using bootstrap-select library for the select fields. The select fields that have className as "selectpicker" do not render, they just aren't there. They showed up when I removed "selectpicker" from the className. When using "selectpicker", they show up when the browser page is reloaded. Below is a snippet from my code: https://codesandbox.io/s

React Routing Redirect onClick

喜夏-厌秋 提交于 2021-02-18 22:30:07
问题 Ive been trying to do a simple redirect to another component on button click, but for some reason it doesnt work.I want to redirect to '/dashboard' and display AdminServices from login as follows: //index.js ReactDOM.render(<BrowserRouter><App /></BrowserRouter>, document.getElementById("root")); //App.js <Switch> <Route path="/" component={Login} /> <Route path="/dashboard" component={AdminServices} /> </Switch> //Login.js <Button onClick={this.login} > </Button> login = () =>{ <Redirect to=

React Router routes not working on nginx create-react-app

拜拜、爱过 提交于 2021-02-18 21:12:07
问题 I'm using "react-router-dom": "^4.2.2" . If I test on localhost:3000/second it works perfectly. When I upload this on ubuntu server with nginx and I try www.website.com , it works . When I try to use www.website.com/second it gives me 404 not found . I'm using create-react-app . app.js class TestRoutes extends React.Component{ constructor(props){ super(props); } render(){ return(<React.Fragment> <BrowserRouter> <Switch> <Route exact path='/' component={MainPage}/> <Route path='/second'

How to test a React component with RouteComponentProps?

天涯浪子 提交于 2021-02-17 18:46:46
问题 I have a component that has props which extend RouteComponentProps that looks like this: export interface RouteComponentProps<P> { match: match<P>; location: H.Location; history: H.History; staticContext?: any; } Now, when I use my component in the app, I pass these props to it: <MyComponent match={this.props.match} location={this.props.location} history={this.props.history} /> The props are available already because it's running inside react router. Now, how do I test this component without