make post and redirect
This commit is contained in:
parent
a9884a4ad7
commit
cf2323cfaf
3 changed files with 8 additions and 3 deletions
2
src/actions/history.js
Normal file
2
src/actions/history.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import { createBrowserHistory } from 'history'
|
||||||
|
export default createBrowserHistory()
|
|
@ -1,4 +1,5 @@
|
||||||
import sudoscientist from '../apis/sudoscientist';
|
import sudoscientist from '../apis/sudoscientist';
|
||||||
|
import history from './history'
|
||||||
|
|
||||||
export const fetchPosts = () => async (dispatch) => {
|
export const fetchPosts = () => async (dispatch) => {
|
||||||
const response = await sudoscientist.get('/blog');
|
const response = await sudoscientist.get('/blog');
|
||||||
|
@ -40,6 +41,6 @@ export const loadCookieToState = (data) => async (dispatch) => {
|
||||||
export const newBlogPost = (payload) => async (dispatch) => {
|
export const newBlogPost = (payload) => async (dispatch) => {
|
||||||
const response = await sudoscientist.post('/blog', payload)
|
const response = await sudoscientist.post('/blog', payload)
|
||||||
if (response.status === 201) {
|
if (response.status === 201) {
|
||||||
console.log('CREATED')
|
history.push('/posts/' + response.data.slug)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
|
import { Router, Route, Switch } from "react-router-dom";
|
||||||
import NavBar from './NavBar';
|
import NavBar from './NavBar';
|
||||||
import Footer from './Footer';
|
import Footer from './Footer';
|
||||||
import PostList from './PostList';
|
import PostList from './PostList';
|
||||||
|
@ -7,11 +7,13 @@ import Post from './Post';
|
||||||
import User from './User';
|
import User from './User';
|
||||||
import About from './About'
|
import About from './About'
|
||||||
import NewPost from './NewPost'
|
import NewPost from './NewPost'
|
||||||
|
import history from '../actions/history';
|
||||||
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Router>
|
<Router history={history}>
|
||||||
<NavBar/>
|
<NavBar/>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path="/" component={PostList}/>
|
<Route exact path="/" component={PostList}/>
|
||||||
|
|
Reference in a new issue