I am new to React.
I was experimenting with states in react.
I have constructed a screen with a form.
sample code looks like this:
var React = require('react');
module.exports = React.createClass({
getInitialState: function(){
return {
attributeName:null,
attributeId:null,
app:null,
URLstate:0
};
},
getDefaultProps: function(){
return{
URI: [
'Create Attribute',
'Edit Attribute'
]
};
},
propTypes: {
URI: React.PropTypes.array
},
handleAttributeNameChange: function (event){
this.setState({
attributeName: event.target.value
});
},
handleAttributeIdChange: function (event) {
this.setState({
attributeId:event.target.value
});
},
handleAppNameChange:function (event) {
this.setState({
app:event.target.value
});
},
handleSubmit:function (event) {
this.setState({
URLstate: (this.state.URLstate + 1) % 2
});
},
render: function(){
return (
<div className = "container">
<h2>{this.props.URI[this.state.URLstate]}</h2>
<div id="attributes" className="form-horizontal">
<div className="form-group">
<label className="col-sm-2 control-label">Attribute Id</label>
<div className = "col-sm-3">
<input type="text" name="AttributeId" placeholder="" onChange={this.handleAttributeIdChange}/>
</div>
</div>
<div className="form-group">
<label className="col-sm-2 control-label">Attribute Name</label>
<div className = "col-sm-3">
<input type="text" name="AttributeName" placeholder="" onChange={this.handleAttributeNameChange}/>
</div>
</div>
<div className="form-group">
<label className="col-sm-2 control-label">App</label>
<div className = "col-sm-3">
<input type="text" name="forApp" placeholder="" onChange={this.handleAppNameChange}/>
</div>
</div>
<div className="form-group">
<div className = "col-sm-3 col-sm-push-2">
<button type="submit" onClick={this.handleSubmit}>submit</button>
</div>
</div>
</div>
</div>
);
}
});
The idea is to change just the title of the component from Create Attribute to Edit Attribute using states.
I have achieved it using the above code.
But the URL after creating a attribute looks some thing like this /createattribute?{query params}.
How can I change the URL(to somthing like editattribute/attributeId) with out actual routing to new page?
Thanks.