Фрагмент кода из Navigation.js
Класс навигации расширяет Компонент {
render () {
возврат (
<Router>
<nav className="navbar navbar-expand-lg navbar-light bg-light">
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarSupportedContent">
<ul className="navbar-nav mr-auto">
<NavDropdown name="Test">
<a className="dropdown-item" >
<li><Link to={"/Invoice"} >Mexico Invoice</Link></li>
</a>
</NavDropdown>
<NavDropdown name="Analysis">
<a className="dropdown-item" href="/Transaction">Audit Log</a>
</NavDropdown>
</ul>
<Route exact path="/Invoice" component={Invoice} />
</div>
</nav>
</Router>
);
}
}
экспорт по умолчанию с помощью роутера (навигация)
Я рендеринг этого компонента из App.js
class App extends Component {
constructor(props) {
super(props);
}
render() {
return (
<Router>
<div >
<HeaderAmex className="App" />
<div>
<Navigation/>
</div>
<Route exact path="/invoice" component={Invoice} />
</div>
</Router>
);
}
}
экспорт по умолчанию с помощью роутера (приложения)
Ниже мой счет-фактура. 1015 *
class Invoice extends Component {
constructor(props) {
super(props);
this.state = { items: [], isLoaded: false, transId: "" ,flag:true,errorFlag:false,show:false,displayContent:"",invoice:"",invoiceXmlBody:"",invoiceTransId:"",invoiceResultFlag:false,invoicedisplayFlag:false};
}
handleChangeInvoice(e) {
console.log("inside handleChangeInvoice");
let invoiceXml = e.target.value;
if (invoiceXml !== undefined) {
this.setState({ invoiceXmlBody: e.target.value });
}
}
handleSubmitInvoiceXml =e=>{
console.log("*******************inside handleSubmitInvoiceXml***************");
let url = "xxxxxx";
fetch(url, {
method: "POST",
body: JSON.stringify(this.state.invoiceXmlBody),
headers: {
"Content-Type": "application/xml"
},
credentials: "xxxxx"
}).then(res => res.json())
.then(json => {
this.setState({
invoiceTransId:json,
});
if(json===undefined){
this.state.invoiceResultFlag=true;
}
else{
this.state.invoicedisplayFlag=true;
console.log("inside=========else===="+this.state.invoicedisplayFlag);
}
}
) }
render() {
const { match, location, history } = this.props
console.log("---------------------------"+this.state.invoicedisplayFlag);
return (
<div className="App">
<div>{location.pathname}</div>
<br/>
<label className="lable" style={{marginRight:19}}>
InvoiceXml:
<input
type="text"
name="invoiceXml" placeholder="Enter invoice xml"
onBlur={this.handleChangeInvoice.bind(this)} style={{marginLeft:15}}
/>
</label><br/><br/>
<input type="button" onClick={this.handleSubmitInvoiceXml} name="Submit" value="Submit" className="submitButton" style={{marginLeft:-60}}/>
<br/>
<br/><br/>
<div className={this.state.invoicedisplayFlag?"showDisplay":"hide"}>
<h5>Transaction Id is :{this.state.invoiceTransId}</h5>
</div>
</div>
);
}
}
export default withRouter(Invoice)
и ниже мой index.js
ReactDOM.render(<App />, document.getElementById('root'));
serviceWorker.unregister();
Может кто-нибудь помочь мне отобразить компонент счета. Я довольно новичок в React.