Skip to content

Commit ac5d2c1

Browse files
committed
fixed redirect issue
1 parent 8352f52 commit ac5d2c1

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
## React API Integration with example of Fetch Axios
1+
## React API Integration with Example using Axios
2+
### Integrate API from [flask-pymongo-validator](https://github.com/mrxmamun/flask-pymongo-validator.git)
23
#### List of Todo API Routes
34
| Request | Endpoint | Details | Example Source |
45
| --- | --- | --- | --- |
5-
| `GET` | `http://127.0.0.1:5000/todos`| Get All| [Todo List](src/components/todo/TodoList.js) |
6-
| `GET` | `http://127.0.0.1:5000/todos/todo_id`| Get Single Id| [Todo](src/components/todo/Todo.js)|
7-
| `POST` | `http://127.0.0.1:5000/todos`| Insert One| [Add Todo](src/components/todo/AddTodo.js)|
8-
| `PUT` | `http://127.0.0.1:5000/todos/todo_id`| Update One| [Update Todo](src/components/todo/Edit.js) |
9-
| `DELETE` | `http://127.0.0.1:5000/todos/todo_id`| Delete One| [Delete Todo](src/components/todo/Todo.js)|
6+
| `GET` | `http://127.0.0.1:5000/api/v1/todos`| Get All| [Todo List](src/components/todo/TodoList.js) |
7+
| `GET` | `http://127.0.0.1:5000/api/v1/todos/todo_id`| Get Single Id| [Todo](src/components/todo/Todo.js)|
8+
| `POST` | `http://127.0.0.1:5000/api/v1/todos`| Insert One| [Add Todo](src/components/todo/AddTodo.js)|
9+
| `PUT` | `http://127.0.0.1:5000/api/v1/todos/todo_id`| Update One| [Update Todo](src/components/todo/Edit.js) |
10+
| `DELETE` | `http://127.0.0.1:5000/api/v1/todos/todo_id`| Delete One| [Delete Todo](src/components/todo/Todo.js)|
1011

1112
### In [Api](src/api.js) File Define all routes
1213
```js

src/App.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@ import { faEdit, faTrash } from '@fortawesome/free-solid-svg-icons'
66
import Navbar from './components/Navbar';
77
import TodoList from "./components/todo/TodoList";
88
import Todo from './components/todo/Todo';
9+
import AddTodo from './components/todo/AddTodo';
910
import TodoEdit from './components/todo/Edit';
1011

1112
library.add(faEdit, faTrash)
1213

13-
1414
class App extends Component {
1515
render() {
1616
return (
1717
<React.Fragment>
1818
<Navbar />
1919
<Switch>
2020
<Route path="/" component={TodoList} exact />
21+
<Route path="/todo/add" component={AddTodo} exact />
2122
<Route path="/todo/:id" component={Todo} exact />
2223
<Route path="/todo/edit/:id" component={TodoEdit} exact />
23-
{/* <Route path="/add/todo" component={AddTodo} exact /> */}
24-
{/*
25-
<Route path="/form" component={MyForm} exact /> */}
24+
2625
</Switch>
2726
</React.Fragment>
2827
);

src/components/todo/AddTodo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AddTodo extends Component {
2323
const {title, body} = this.state;
2424
// define state variable for use in return
2525
//and store in state value
26-
api.todos().create({ title: title, body: body})
26+
api.todos().create({ title: title, body: body})
2727
.then(response => response.data)
2828
.then(this.setState({ //clear inputs after submit
2929
title: "",

src/components/todo/Edit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class Todo extends Component {
1818
title: response.data.title,
1919
body: response.data.body
2020
}));
21-
2221
}
2322
onChance = (e) => {
2423
this.setState({ [e.target.name]: e.target.value });
@@ -30,6 +29,8 @@ class Todo extends Component {
3029
const { title, body } = this.state; // define state variable for use in return and store in state value
3130
api.todos().update(todoId, { title: title, body: body })
3231
.then(response => response.data);
32+
33+
this.props.history.push('/');
3334
}
3435

3536

src/components/todo/Todo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class Todo extends Component {
1717
api.todos().getOne(todoId)
1818
.then(response => this.setState({ todo: response.data }));
1919
}
20-
2120
onDelete = () => {
2221
const todoId = this.props.match.params;
2322
api.todos().delete(todoId);
23+
this.props.history.push('/');
2424
}
2525

2626
render() {

0 commit comments

Comments
 (0)