react-router

ReactJS HREF Causes State Loss

梦想的初衷 提交于 2021-02-11 14:35:10
问题 I have a parent component called EnrollForm with a BrowserRouter that routes to different sub-components which are the pages of my overall EnrollForm. Each time a sub-component page is filled out and next btn is clicked, all form fields are saved to sub-component state obj, then that state is passed to the parent EnrollForm state. This flow is working correctly.. however when I added the line of code to href to the next sub-component, the parent EnrollForm state is deleted and so is BioForm's

How to trick react router into thinking `/` is the mount directory?

旧时模样 提交于 2021-02-11 14:13:49
问题 Let's say I have a simple react app: import React from 'react'; import ReactDOM from 'react-dom'; import {BrowserRouter as Router, Route} from 'react-router-dom' import * as serviceWorker from './serviceWorker'; import App from './App'; import About from './components/pages/About' import Header from './components/layout/Header'; ReactDOM.render( <React.StrictMode> <Router> <Route path = "/" component={Header} /> <Route exact path="/" component= {App} /> <Route path="/about" component = {About

React Router URL Change but Not Component

痞子三分冷 提交于 2021-02-11 13:23:29
问题 React Router change the URL but the component is not rendered I have already looked for answer but none of those example is worked Current React Router & React Router DOM version is 5.0.0 It's still plain create-react-app I've tried to use Switch tag import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; import { BrowserRouter as Router, Route, Link } from 'react-router-dom'; const Index = () => { return <h2>Home</h2>; }; const About = () => { return <h2

this.props.history showing undefine in console in React JS

百般思念 提交于 2021-02-11 13:19:17
问题 In my react app I want to send state to the next path through the history.location.state and history.location.pathname In my case, it has to push successfully and also showing in history but when I console.log(this.props.history) in the child page showing undefined. MyComponent Code import React, { Component } from 'react'; import { withRouter } from 'react-router-dom'; class MyComponent extends Component { state = { cart: { 1:{ icon: "URL" id: 1 quantity: 1 title: "item1" } 2:{ icon: "URL"

this.props.history showing undefine in console in React JS

时光毁灭记忆、已成空白 提交于 2021-02-11 13:19:04
问题 In my react app I want to send state to the next path through the history.location.state and history.location.pathname In my case, it has to push successfully and also showing in history but when I console.log(this.props.history) in the child page showing undefined. MyComponent Code import React, { Component } from 'react'; import { withRouter } from 'react-router-dom'; class MyComponent extends Component { state = { cart: { 1:{ icon: "URL" id: 1 quantity: 1 title: "item1" } 2:{ icon: "URL"

React-router route won't trigger

我是研究僧i 提交于 2021-02-11 12:50:45
问题 First, i am sorry if this problem has been asked before. I am currently new to react-router, i don't know what to ask. So, i am trying to make a sidebar component in my apps, this sidebar composed of material-ui drawer, listItems. Each listItem has a link i put as its containerElement attribute value. Selecting each list does change the url, but component that each route should display won't show. Here is my code: App.js import React, { Component } from 'react' import MuiThemeProvider from

React-router route won't trigger

会有一股神秘感。 提交于 2021-02-11 12:50:17
问题 First, i am sorry if this problem has been asked before. I am currently new to react-router, i don't know what to ask. So, i am trying to make a sidebar component in my apps, this sidebar composed of material-ui drawer, listItems. Each listItem has a link i put as its containerElement attribute value. Selecting each list does change the url, but component that each route should display won't show. Here is my code: App.js import React, { Component } from 'react' import MuiThemeProvider from

Is it possible to change route on scroll?

爷,独闯天下 提交于 2021-02-11 12:36:12
问题 I want to load multiple components on a single page and have different routes for all of them. For example i hit a route /article/1 and it loads a component, after scrolling through completely through that article i want the route to change to /article/2 and the corresponding article to load. I am using react and react router, basically i want 4 (article/3 , article/4) articles on a page and all these should be scrollable with the route changing as i scroll onto a particular article. How can

Router rendering the component on the same page rather than rendering in a new page

半腔热情 提交于 2021-02-11 12:05:15
问题 Router is rendering the page on the same page than to generate a new page. What might be the problem? Whenever I click the link Polls , it renders the page only there but the URL is shown as changed in the browser. Polls.js import React from 'react'; import {Link} from "react-router-dom"; class Polls extends React.Component{ render() { return( <div> <h1>Polls Page</h1> <p>This is Polls Page </p> </div> ) } } export {Polls} Choices.js import { BrowserRouter as Router, Route, Link } from "react

React Router + back button is resetting my app state

人盡茶涼 提交于 2021-02-11 06:55:27
问题 I'm using React Router Dom and the BrowserRouter object to enable browser based navigation for a site I'm building. Navigation works well, but if a user hits the back button, the entirety of my App's state is wiped clean. I'm not sure why this is happening. I've tried searching around, but all of the answers I've found don't mention why App state is getting reset. Here's my implementation: <BrowserRouter> <Switch> <Route path="/" exact render={()=><LandingPage/>} <Route path="/about" render={