From cf2323cfaf8c246a09b3631e78e550079f451929 Mon Sep 17 00:00:00 2001 From: Asara Date: Mon, 21 Oct 2019 21:02:37 -0400 Subject: [PATCH] make post and redirect --- src/actions/history.js | 2 ++ src/actions/index.js | 3 ++- src/components/App.js | 6 ++++-- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/actions/history.js diff --git a/src/actions/history.js b/src/actions/history.js new file mode 100644 index 0000000..19409ad --- /dev/null +++ b/src/actions/history.js @@ -0,0 +1,2 @@ +import { createBrowserHistory } from 'history' +export default createBrowserHistory() diff --git a/src/actions/index.js b/src/actions/index.js index a3f017b..66b71ab 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -1,4 +1,5 @@ import sudoscientist from '../apis/sudoscientist'; +import history from './history' export const fetchPosts = () => async (dispatch) => { const response = await sudoscientist.get('/blog'); @@ -40,6 +41,6 @@ export const loadCookieToState = (data) => async (dispatch) => { export const newBlogPost = (payload) => async (dispatch) => { const response = await sudoscientist.post('/blog', payload) if (response.status === 201) { - console.log('CREATED') + history.push('/posts/' + response.data.slug) } }; diff --git a/src/components/App.js b/src/components/App.js index 1c73f2a..e02f214 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,5 +1,5 @@ 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 Footer from './Footer'; import PostList from './PostList'; @@ -7,11 +7,13 @@ import Post from './Post'; import User from './User'; import About from './About' import NewPost from './NewPost' +import history from '../actions/history'; + function App() { return ( <> - +