के नए प्रतिक्रिया-राउटर-डोम में रीडायरेक्ट का उपयोग कैसे करें मैं पिछले संस्करण प्रतिक्रिया-राउटर मॉड्यूल का उपयोग कर रहा हूं, जिसका नाम प्रतिक्रिया-राउटर-डोम है, जो वेब अनुप्रयोगों को विकसित करने के लिए डिफ़ॉल्ट रूप से बन गया है। मैं जानना चाहता हूं कि POST अनुरोध के बाद पुनर्निर्देशन कैसे करें। मैं यह कोड बना रहा हूं, लेकिन अनुरोध के बाद, कुछ भी नहीं होता है। मैं वेब पर समीक्षा करता हूं, लेकिन सभी डेटा प्रतिक्रिया राउटर के पिछले संस्करणों के बारे में है, और अंतिम अद्यतन के साथ नहीं।Reactjs
कोड:
import React, { PropTypes } from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { Redirect } from 'react-router'
import SignUpForm from '../../register/components/SignUpForm';
import styles from './PagesStyles.css';
import axios from 'axios';
import Footer from '../../shared/components/Footer';
class SignUpPage extends React.Component {
constructor(props) {
super(props);
this.state = {
errors: {},
client: {
userclient: '',
clientname: '',
clientbusinessname: '',
password: '',
confirmPassword: ''
}
};
this.processForm = this.processForm.bind(this);
this.changeClient = this.changeClient.bind(this);
}
changeClient(event) {
const field = event.target.name;
const client = this.state.client;
client[field] = event.target.value;
this.setState({
client
});
}
async processForm(event) {
event.preventDefault();
const userclient = this.state.client.userclient;
const clientname = this.state.client.clientname;
const clientbusinessname = this.state.client.clientbusinessname;
const password = this.state.client.password;
const confirmPassword = this.state.client.confirmPassword;
const formData = { userclient, clientname, clientbusinessname, password, confirmPassword };
axios.post('/signup', formData, { headers: {'Accept': 'application/json'} })
.then((response) => {
this.setState({
errors: {}
});
<Redirect to="/"/> // Here, nothings happens
}).catch((error) => {
const errors = error.response.data.errors ? error.response.data.errors : {};
errors.summary = error.response.data.message;
this.setState({
errors
});
});
}
render() {
return (
<div className={styles.section}>
<div className={styles.container}>
<img src={require('./images/lisa_principal_bg.png')} className={styles.fullImageBackground} />
<SignUpForm
onSubmit={this.processForm}
onChange={this.changeClient}
errors={this.state.errors}
client={this.state.client}
/>
<Footer />
</div>
</div>
);
}
}
export default SignUpPage;
आपका 'रीडायरेक्ट' जेएसएक्स की तरह दिखता है, जेएस नहीं। – elmeister
क्या आप आपको पूरा घटक कोड – KornholioBeavis
प्रदान कर सकते हैं हां, मैं जेएसएक्स का उपयोग कर रहा हूं। खैर, शायद मुझे स्पष्टीकरण की जरूरत है। POST अनुरोध एक REACT घटक के अंदर है जो अनुरोध करता है। – maoooricio