I created a web-app that uses reactjs. Now the basics of the app are :
Create Topics/Sub topics. Display them (this uses react ) Now 2nd task is explained as :-
Show all the topics/sub topics list. Clicking any of them sends json req and the data is recieved and displayed. Now I want to share the topic with link , however on clicking any of the topic only one elemnt of the html renders and the url remains the same.
So this is what i want to do -
On clicking , send json req and recieve data ( done ) Change the url ( I want to know if it is possible using the same react page? )
How can I use Routes in the following code ?
Part 1 :- Deals with recents posts Part 2 :- Deals with the Headings or Topic names Part 3 :- Deals with Sub topics Part 4 :- Deals with showing the Article from the chosen topic and sub topic.
Now its obvious that though the article is displayed , the link / url of the page will never change. However it makes it hard to share the articles. Thus I want to know how to apply the routes in this case ?
render() {
var lists = this.state.list;
var lists2 = this.state.list2;
var aname = this.state.article.name;
var date = this.state.article.date;
var lists3 = this.state.listrec;
return (
<div className="row">
<div id="recentsbar" className="col-md-3">
<div className="row">
<div className="col-md-9">
<div>
<div style={{ display: this.state.hide2 }}>
<h2>
<b> Recents </b>
</h2>
<div
className="lds-ellipsis"
style={{ display: this.state.load2 }}
>
<div />
<div />
<div />
<div />
</div>
<div id="subl">
{lists3.map(number => (
<Item3 name={number} show={this.rec.bind(this)} />
))}
</div>
</div>
</div>
</div>
</div>
</div>
<div className="col-md-8">
<div style={{ display: this.state.hide }}>
<h1 style={{ marginLeft: 6 + "em" }}>
<b> Subjects List </b>
</h1>
<div className="row">
<div className="col-md-6">
<ul style={{ marginTop: 1 + "em" }} /*className="list-group"*/>
<div
className="lds-ellipsis"
style={{ display: this.state.load }}
>
<div />
<div />
<div />
<div />
</div>
{lists.map(number => (
<Item name={number} hide={this.hide.bind(this)} />
))}
</ul>
</div>
</div>
</div>
<div className="col-md-8">
<div style={{ display: this.state.show }}>
<h1 style={{ marginLeft: 6 + "em" }}>
<b> {this.state.selsub} </b>
</h1>
<div className="row">
<div className="col-md-auto" style={{ marginLeft: 6 + "em" }}>
<ul
style={{ marginTop: 1 + "em" }}
className="list-group art"
>
<div
className="lds-ellipsis"
style={{ display: this.state.load }}
>
<div />
<div />
<div />
<div />
</div>
{lists2.map(number => (
<Item2 name={number} hide2={this.hide2.bind(this)} />
))}
</ul>
</div>
</div>
</div>
</div>
<div style={{ display: this.state.showarticle }}>
<div className="lds-ellipsis" style={{ display: this.state.load }}>
<div />
<div />
<div />
<div />
</div>
<div className="arthead"> {aname} </div>
<div style={{ float: "right", opacity: 0.5 }}>
Updated on: {date}{" "}
</div>
<div
style={{
marginLeft: 1 + "em",
lineHeight: 2 + "em",
marginTop: 4 + "em"
}}
dangerouslySetInnerHTML={{ __html: this.state.article.body }}
/>
</div>
</div>
</div>
);
}