diff --git a/fittrackee_client/src/utils/history.js b/fittrackee_client/src/utils/history.js index 3da7b17f..5d2209af 100644 --- a/fittrackee_client/src/utils/history.js +++ b/fittrackee_client/src/utils/history.js @@ -1,15 +1,24 @@ +const updatePath = (toPath, newPath) => { + if (typeof toPath === 'string' || toPath instanceof String) { + toPath = newPath + } else { + toPath.pathname = newPath + } + return toPath +} + const pathInterceptor = toPath => { if ( !window.localStorage.authToken && !['/login', '/register'].includes(toPath.pathname) ) { - toPath.pathname = '/login' + toPath = updatePath(toPath, '/login') } if ( window.localStorage.authToken && ['/login', '/register'].includes(toPath.pathname) ) { - toPath.pathname = '/' + toPath = updatePath(toPath, '/') } return toPath }