Skip to content

Commit 5450228

Browse files
authored
Merge pull request #12 from manjeetaR/nav-route
fixed router navigation
2 parents b99dc4c + 1c05679 commit 5450228

File tree

3 files changed

+74
-71
lines changed

3 files changed

+74
-71
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"react": "^16.6.0",
6565
"react-dom": "^16.6.0",
6666
"react-markdown": "^4.0.6",
67+
"react-router-dom": "^5.1.2",
6768
"reactstrap": "^6.5.0"
6869
},
6970
"husky": {

src/App.js

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Fragment, Component } from "react";
22
import { Button } from 'reactstrap';
3-
3+
import { BrowserRouter, Route } from 'react-router-dom';
44
import Navigation from './Components/Navigation';
55
import Main from './Components/Main';
66
import Herocontent from './Components/Herocontent';
@@ -10,51 +10,50 @@ import AppMarkdown from '../README.md';
1010
const markdownContext = require.context('../docs', false, /\.md$/);
1111
const markdownFiles = markdownContext
1212
.keys()
13-
//.map((filename) => markdownContext(filename))
13+
//.map((filename) => markdownContext(filename))
1414
//console.log("hey"+markdownFiles);
1515

1616
class App extends React.Component {
17-
constructor(props){
17+
constructor(props) {
1818
super(props);
1919
this.state = {
20-
count : 5,
21-
posts1 : []
22-
}
20+
count: 5,
21+
posts1: []
22+
}
2323
}
24-
24+
2525
componentDidMount() {
2626
var newPosts = [];
2727
const posts = markdownFiles.forEach(
28-
(file, key ) => {
29-
newPosts.push({
30-
id: key,
31-
data: "."+file
32-
});
33-
}
34-
);
28+
(file, key) => {
29+
newPosts.push({
30+
id: key,
31+
data: "." + file
32+
});
33+
}
34+
);
3535

3636
newPosts.map(
37-
(post) =>
38-
{
39-
let a =10;
40-
console.log("new values===>"+post.data);
41-
let av = this.apiGetAll(post.data);
42-
console.log("json--->"+JSON.stringify(av));
43-
}
44-
);
37+
(post) => {
38+
let a = 10;
39+
console.log("new values===>" + post.data);
40+
let av = this.apiGetAll(post.data);
41+
console.log("json--->" + JSON.stringify(av));
42+
}
43+
);
4544
//this.apiGetAll(newPosts["data"]);
4645
return false;
4746
}
4847

49-
async apiGetAll (newPosts) {
48+
async apiGetAll(newPosts) {
5049
let cc = [];
5150
try {
52-
const resp = await fetch(newPosts).then( res => res.text() );
53-
console.log("fetch---"+resp);
51+
const resp = await fetch(newPosts).then(res => res.text());
52+
console.log("fetch---" + resp);
5453
cc.push({
55-
data : resp
54+
data: resp
5655
});
57-
console.log("json--->"+JSON.stringify(cc));
56+
console.log("json--->" + JSON.stringify(cc));
5857
/* const newResp = await Promise.all((resp)).then(result => {
5958
console.log("hey--->"+result);
6059
this.setState({posts1: result});
@@ -65,7 +64,7 @@ class App extends React.Component {
6564
} catch (err) {
6665
console.log(err);
6766
}
68-
}
67+
}
6968

7069
/*getFileResults(newPosts) {
7170
let data = [];
@@ -92,30 +91,32 @@ class App extends React.Component {
9291
});
9392
}*/
9493

95-
render() {
94+
render() {
9695
return (
9796
<div>
98-
<Navigation />
99-
<Herocontent />
100-
<Main />
101-
<Fragment>
102-
<section className="section">
103-
<div className="container">
104-
<div className="card">
105-
<div className="card-content">
106-
<div className="content">
107-
{
108-
//newPosts.map((post, idx) => (
109-
// this.state.posts1
110-
// ))
111-
}
112-
<ReactMarkdown source={this.state.posts1} />
97+
<BrowserRouter>
98+
<Navigation />
99+
<Herocontent />
100+
<Route exact path="/" component={Main} />
101+
<Fragment>
102+
<section className="section">
103+
<div className="container">
104+
<div className="card">
105+
<div className="card-content">
106+
<div className="content">
107+
{
108+
//newPosts.map((post, idx) => (
109+
// this.state.posts1
110+
// ))
111+
}
112+
<ReactMarkdown source={this.state.posts1} />
113+
</div>
113114
</div>
114115
</div>
115116
</div>
116-
</div>
117-
</section>
118-
</Fragment>
117+
</section>
118+
</Fragment>
119+
</BrowserRouter>
119120
</div>
120121
);
121122
}

src/Components/Main.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11

22
import React from 'react';
3-
import {titleMetaData} from './data';
3+
import { Link } from 'react-router-dom'
4+
import { titleMetaData } from './data';
45

56
class Main extends React.Component {
6-
constructor(props){
7+
constructor(props) {
78
super(props);
89
this.state = {
9-
count : 5,
10-
posts1 : []
11-
}
10+
count: 5,
11+
posts1: []
12+
}
1213
}
13-
14+
1415
componentDidMount() {
1516
//console.log(JSON.stringify(titleMetaData));
1617
}
1718

1819
render() {
19-
return(
20+
return (
2021
<div className="main thememain-white">
2122
{
22-
titleMetaData.map( (title) =>
23-
<div className="container content-main">
24-
<div className="row">
25-
<div className="col-12">
26-
<h3>{ title.labelTitle }</h3>
27-
</div>
23+
titleMetaData.map((title) =>
24+
<div className="container content-main">
25+
<div className="row">
26+
<div className="col-12">
27+
<h3>{title.labelTitle}</h3>
2828
</div>
29-
<div className="row">
30-
<div className="col-sm">
31-
<ul>
32-
{title.topics.map((topics) =>
33-
<li><a href={topics.url}>{topics.title}</a></li>
34-
)}
35-
</ul>
36-
</div>
29+
</div>
30+
<div className="row">
31+
<div className="col-sm">
32+
<ul>
33+
{title.topics.map((topics) =>
34+
<li><Link to={topics.url}>{topics.title}</Link></li>
35+
)}
36+
</ul>
3737
</div>
3838
</div>
39-
)
40-
}
41-
</div>
39+
</div>
40+
)
41+
}
42+
</div>
4243
);
4344
}
4445
}

0 commit comments

Comments
 (0)