diff --git a/ui/js/actions/app.js b/ui/js/actions/app.js index b943f5e4b..d233166dc 100644 --- a/ui/js/actions/app.js +++ b/ui/js/actions/app.js @@ -20,14 +20,9 @@ export function doNavigate(path) { const state = getState() const previousPath = selectCurrentPath(state) const previousTitle = selectPageTitle(state) - history.pushState(state, previousTitle, previousPath); + history.pushState({}, previousTitle, previousPath); - dispatch({ - type: types.NAVIGATE, - data: { - path, - } - }) + dispatch(doChangePath(path)) const pageTitle = selectPageTitle(state) @@ -35,6 +30,15 @@ export function doNavigate(path) { } } +export function doChangePath(path) { + return { + type: types.CHANGE_PATH, + data: { + path, + } + } +} + export function doLogoClick() { } diff --git a/ui/js/constants/action_types.js b/ui/js/constants/action_types.js index 14f6c7b88..42a4eba3f 100644 --- a/ui/js/constants/action_types.js +++ b/ui/js/constants/action_types.js @@ -1,4 +1,4 @@ -export const NAVIGATE = 'NAVIGATE' +export const CHANGE_PATH = 'CHANGE_PATH' export const OPEN_MODAL = 'OPEN_MODAL' export const CLOSE_MODAL = 'CLOSE_MODAL' export const HISTORY_BACK = 'HISTORY_BACK' diff --git a/ui/js/main.js b/ui/js/main.js index d94093f24..d7ed5f178 100644 --- a/ui/js/main.js +++ b/ui/js/main.js @@ -11,7 +11,8 @@ import { Provider } from 'react-redux'; import store from 'store.js'; import { runTriggers } from 'triggers' import { - doDaemonReady + doDaemonReady, + doChangePath, } from 'actions/app' const {remote} = require('electron'); @@ -26,6 +27,18 @@ window.addEventListener('contextmenu', (event) => { event.preventDefault(); }); +window.addEventListener('popstate', (event) => { + let pathname = document.location.pathname + if (pathname.match(/dist/)) + pathname = '/discover' + + app.store.dispatch(doChangePath(pathname)) +}) + +if (window.location.hash != '') { + window.history.pushState({}, "Discover", location.hash.substring(2)); +} + const initialState = app.store.getState(); app.store.subscribe(runTriggers); runTriggers(); diff --git a/ui/js/reducers/app.js b/ui/js/reducers/app.js index 77e67a0bb..751c38a53 100644 --- a/ui/js/reducers/app.js +++ b/ui/js/reducers/app.js @@ -19,7 +19,7 @@ reducers[types.DAEMON_READY] = function(state, action) { }) } -reducers[types.NAVIGATE] = function(state, action) { +reducers[types.CHANGE_PATH] = function(state, action) { return Object.assign({}, state, { currentPath: action.data.path, }) diff --git a/ui/js/selectors/app.js b/ui/js/selectors/app.js index c72786747..c3932a695 100644 --- a/ui/js/selectors/app.js +++ b/ui/js/selectors/app.js @@ -22,7 +22,7 @@ export const selectCurrentPage = createSelector( (path, searchActivated) => { if (searchActivated) return 'search' - return path.split('=')[0] + return path.replace(/^\//, '').split('=')[0] } )