react-router

Redirect on Login - React.js

余生长醉 提交于 2020-04-08 07:30:52
问题 I am trying to do a simple Redirect with React Router after my user successfully logs in (inside Login.js), and prevent the user from revisiting the login page (inside index.js). In Login.js, I have onSubmit={this.handleSubmit} within the login button tag, and handleSubmit(e) function to Redirect. I have tried a few other solutions online, but I think my understanding on the usage of the <Redirect/> component is wrong. In index.js, I have a conditional that tests if the user is signed in, or

PrivateRouting when Token in Local Storage [TypeScript]

早过忘川 提交于 2020-03-28 06:41:49
问题 If my login in successful, an authentication token is returned, which is stored in the local storage. Upon successful login, I want to go the a private route. I found this code Javascript snippet but I am unable to make it work for Typescript. I don't have any isAuthenthicated property yet. How could I modify this accordingly? const PrivateRoute = ({ component: Component, ...rest }) => ( <Route {...rest} render={props => ( fakeAuth.isAuthenticated ? ( <Component {...props}/> ) : ( <Redirect

react-router-dom@4.0.0 requires a peer of react@^15 but none is installed. You must install peer dependencies yourself

筅森魡賤 提交于 2020-03-21 11:56:30
问题 I have installed all required libraries using npm install and I also done npm install --save react-router-dom@4.0.0 but I am still getting this error. My Package.json "author": "", "license": "ISC", "devDependencies": { "babel-core": "^6.2.1", "babel-loader": "^6.2.0", "babel-preset-es2015": "^6.1.18", "babel-preset-react": "^6.1.18", "chai": "^3.5.0", "chai-jquery": "^2.0.0", "jquery": "^2.2.1", "jsdom": "^8.1.0", "mocha": "^2.4.5", "react-addons-test-utils": "^0.14.7", "webpack": "^1.12.9",

TypeError: date[(“get” + method)] is not a function in React-big-calendar

廉价感情. 提交于 2020-03-19 04:01:24
问题 I am trying to change the view from month to week but in meantime it give me an error . I am new to react and react-big-calendar could someone please help me how to solve this problem . When I change calendar view to month it working fine but when I changed it to week or day so it give me an error. please help me Thanks Code import React, { Component } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import MyCalendar from 'react-big-calendar';

How to set route with optional query parameter using React router?

孤者浪人 提交于 2020-03-18 12:33:25
问题 I have a path as <Route path="/account/:accountid/LoginPage" component={LoginPage}/> This works fine if the url is -> /account/12332/LoginPage . I want to have optional query parameters. Url structure would be something as /account/12322/LoginPage?User=A&User=B I have modified the path as <Route path="/account/:accountid/LoginPage(/:User)" component={LoginPage}/> after this if I try to access the url it does not redirect me to the appropriate page instead it throws an error as useBasename.js

Fastest way to add pre-existing static HTML page to a React/Gatsby site

拈花ヽ惹草 提交于 2020-03-18 05:14:08
问题 I have a simple project working nicely using JSX / React / Gatsby. I have a pre-existing page (think landing page) in HTML in another project, quite complex, nicely styled using Bootstrap 4, let's call it LandingPage.html and an associated LandingPage.css. I would like to add the landing page to my Gatsby site. So that for example when navigating to localhost:3000/LandingPage.html the landing page gets shown, properly styled etc. I am not clear whether I have to fully convert my pre-existing

How to fix losing focus after 1 character with React-Router

半城伤御伤魂 提交于 2020-03-05 02:42:17
问题 An input element loses focus after typing one character. This SO question has some answers, suggesting to add the id or key property, however, I could not fix my problem this way. Then I pinpointed the problem to react-router-dom . This has the problem: <Route path='xxx' component={() => <TheComponent... />} where TheComponent contains the input element that loses focus while typing. This did not fix the problem: <Route id='1' path='xxx' component={() => <TheComponent... />} Changing the id

ReactJs Problem with displaying home page after user logs-in

江枫思渺然 提交于 2020-03-05 00:25:14
问题 I am using passport.js and jwt token to handle the user authentication state in my react app. After the user logs-in, I store the token in localStorage and so depending on whether there's a token or not in the localStorage, I will updated the isAuthenticated state property. Now, when a guest user (non-authenticated) user, opens the app, he should not be able to access the home-page of the app. So I devided the routes that the guest user can access and the authenticated user can access to two

Force remount component when click on the same react router Link multiple times

℡╲_俬逩灬. 提交于 2020-03-04 23:06:13
问题 I have a route page with a datatable fetch data when component mount. When I click on the same react-router-dom Link (to the route above) multiple times, it seems like component only unmount when the route change (with different component to be render). I want the component to be forced remount when click on the same link again in order to fetch new data. Are there any options in react-router-dom Link or any other Link component or any trick to do this? My sample code here: https:/

Force remount component when click on the same react router Link multiple times

雨燕双飞 提交于 2020-03-04 23:05:23
问题 I have a route page with a datatable fetch data when component mount. When I click on the same react-router-dom Link (to the route above) multiple times, it seems like component only unmount when the route change (with different component to be render). I want the component to be forced remount when click on the same link again in order to fetch new data. Are there any options in react-router-dom Link or any other Link component or any trick to do this? My sample code here: https:/