react-router

disable back button in react-router 2

[亡魂溺海] 提交于 2020-05-11 10:18:06
问题 I am using react-router 2. My routes are defined as <Route path="/" component={App}> <IndexRoute component={Home}/> <Route path="/about" component={About}/> <Route path="/login" component={Login} onEnter={redirectToDashboard}/> <Route path="/logout" component={Logout} onEnter={logoutSession}/> <Route path="/dashboard" component={Dashboard} onEnter={redirectToLogin}/> </Route> Everything working fine but I am having problem disabling back button from my dashboard page. After successful login I

Next.js: Router.push with state

浪尽此生 提交于 2020-05-11 06:35:09
问题 I'm using next.js for rebuilding an app for server side rendering. I have a button that handles a search request. In the old app, the handler was this one: search = (event) => { event.preventDefault(); history.push({ pathname: '/results', state: { pattern: this.state.searchText, } }); } In the results class, I could get the state date with this.props.location.state.pattern. So now I'm using next.js: import Router, { withRouter } from 'next/router' performSearch = (event) => { event

How to Access History Object Outside of a React Component

十年热恋 提交于 2020-05-11 03:44:11
问题 First of all, I am pretty familiar with the withRouter HoC, however, in this case, it doesn't help because I do not want to access the history object in a component. I am trying to achieve a mechanism that will redirect the user to the login page if I receive back a 401 from a API endpoint. For making http requests I am using axios. I have around 60 endpoints that I need to cover, that are used in a dozen of components throughout my app. I want to create a decorator function to the axios

this.props.history.push works in some components and not others

喜你入骨 提交于 2020-05-09 19:08:14
问题 I am trying to programmatically change pages using browserHistory.push . In one of my components, but not in a component that I embedded inside of that one. Does anyone know why my project is throwing the error below only for the child component but not for the parent component? Cannot read property 'push' of undefined Parent Component import React, {Component} from 'react'; import { browserHistory } from 'react-router'; import ChildView from './ChildView'; class ParentView extends Component

React-Router open Link in new tab

前提是你 提交于 2020-05-09 18:10:45
问题 Is there a way to get React Router to open a link in new tab? I tried this and it did not work. <Link to="chart" target="_blank" query={{test: this.props.test}} >Test</Link> It's possible to fluff it by adding something like onClick="foo" to the Link like what I have above, but there would be a console error. Thanks. 回答1: I think Link component does not have the props for it. You can have alternative way by create a tag and use the makeHref method of Navigation mixin to create your url <a

React router sidebar routes correctly but doesn't show the component under the top menu

安稳与你 提交于 2020-04-30 07:13:21
问题 I have designed a management panel in React with a sidebar and a top menu. when you click on any links on the sidebar, a component needs to be shown under the top menu. But even though the router links work correctly (they change the URL and they show the single component when I load the router link separately), they don't show anything under the top menu and next to the sidebar when I click on the sidebar links. what seems to be the problem? Edit: the github link of the project, its actually

How to setup dynamic routing with React Router based on props received?

允我心安 提交于 2020-04-30 06:32:50
问题 I have created a blogging App in react JS and would like to change the URL path when navigating to a blog article. However, I am running into a problem when using '/:id' in Route with React Router Dom. Example when navigating to these two URLs: Blog article URL: https://website.com/myfirstblogpost/4582819 Profile page URL: https://website.com/profile/902310 App.js setup <Route path="/:id/:id" component={BlogArticle} exact={true} /> <Route path="/profile/:id" component={Profile} exact={true}/>

Stop Redirection onSubmit() & Display Error Message Instead

时光总嘲笑我的痴心妄想 提交于 2020-04-18 12:31:21
问题 I have a login screen. If the username & password are correct, a token is stored in local storage. If not, I was printing an error message "Login Unsuccessful". It was working properly. But Now, I have added redirection into my code. If the username & password are correct, I have to go to /panel. If not, I have to display the error message. However, currently, if the username & password are incorrect, I just go to /404 page immediately. How can I fix this? I only want to go to /404 if a wrong

React Router Routes Don't work when deployed to Heroku

拜拜、爱过 提交于 2020-04-18 05:49:23
问题 Using Node/express/React with MySQL/Sequelize I have a branch of my create react app app here: https://github.com/geochanto/nutrient-calculator-react/commits/edit-recipe Which I'm deploying to Heroku here: https://nameless-temple-93876.herokuapp.com/ Locally both backend (expressjs) and frontend (React Router) routes work fine. Problem: on Heroku, while backend routes do work, only the root('/') react route works. Other routes just give a blank white page instead of loading respective

Can React-Router point directly to a route defined with Express instead of rendering a component?

北城余情 提交于 2020-04-18 05:45:32
问题 How I can use React-Router to point directly to a route defined with Express on the backend instead of rendering a component? I want to return valid JSON with no HTML included in the response. 回答1: React-Router only handles routing on the React frontend. There is no way for React-Router to point to an Express Route on the back end. A React component would have to use that API endpoint. Why not just hit the endpoint manually. 来源: https://stackoverflow.com/questions/61162675/can-react-router