From d6adef26eb96b20243bdea9c2d62a10e2cb1888c Mon Sep 17 00:00:00 2001 From: horhik Date: Sun, 14 Jun 2020 15:39:46 +0300 Subject: [PATCH] fixed: routes from url --- .idea/workspace.xml | 9 +++++---- src/App.js | 22 ++++++++++++++++++++-- src/reducers/client-reducer.js | 1 + 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 26ec1be..694a642 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -12,7 +12,8 @@ - + + @@ -145,12 +146,12 @@ - + - + diff --git a/src/App.js b/src/App.js index 268e505..26aae6a 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,4 @@ -import React from "react"; +import React, {useEffect} from "react"; import "./css/basic.scss"; import HomePage from "./components/pages/homepage"; import { connect } from "react-redux"; @@ -9,7 +9,23 @@ import Logo from "./components/elements/logo"; import PortfolioPage from "./components/pages/portfolio"; import BlogPage from "./components/pages/blog"; import pages from "./constants/routes"; +import {setCurrentPage} from "./actions/route-actions"; + function App(props) { + useEffect(() => { + const path = window.location.pathname + switch (path) { + case pages[1].src: + props.setCurrentPage(pages[1]) + return 0 + case pages[2].src: + props.setCurrentPage(pages[2]) + return 0 + default: + props.setCurrentPage(pages[0]) + return 0 + } + }, [] ) return (
@@ -42,4 +58,6 @@ export default connect((state) => ({ currentPage: state.client.currentPage, currentPageName: state.client.currentPageName, pageQuote: state.client.pageQuote, -}))(App); +}), { + setCurrentPage +})(App); diff --git a/src/reducers/client-reducer.js b/src/reducers/client-reducer.js index a546fba..bd916e5 100644 --- a/src/reducers/client-reducer.js +++ b/src/reducers/client-reducer.js @@ -14,6 +14,7 @@ const initialState = { const clientReducer = (state = initialState, action) => { switch (action.type) { case SET_CURRENT_PAGE: + console.log(action.page.src, "SWITCH") return { ...state, currentPath: action.page.src,