Merge pull request #10181 from BerkeleyTrue/fix/user-sensitive-routes
Fix(routes): user sensitive routes redirect to map
This commit is contained in:
@ -5,7 +5,7 @@ import { compose, createStore, applyMiddleware } from 'redux';
|
|||||||
// main app
|
// main app
|
||||||
import App from './App.jsx';
|
import App from './App.jsx';
|
||||||
// app routes
|
// app routes
|
||||||
import childRoutes from './routes';
|
import createChildRoute from './routes';
|
||||||
|
|
||||||
// redux
|
// redux
|
||||||
import { createEpic } from 'redux-epic';
|
import { createEpic } from 'redux-epic';
|
||||||
@ -17,8 +17,6 @@ import servicesCreator from '../utils/services-creator';
|
|||||||
|
|
||||||
const createRouteProps = Observable.fromNodeCallback(match);
|
const createRouteProps = Observable.fromNodeCallback(match);
|
||||||
|
|
||||||
const routes = { components: App, ...childRoutes };
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// createApp(settings: {
|
// createApp(settings: {
|
||||||
// location?: Location|String,
|
// location?: Location|String,
|
||||||
@ -75,7 +73,12 @@ export default function createApp({
|
|||||||
// sync history client side with store.
|
// sync history client side with store.
|
||||||
// server side this is an identity function and history is undefined
|
// server side this is an identity function and history is undefined
|
||||||
history = syncHistoryWithStore(history, store, syncOptions);
|
history = syncHistoryWithStore(history, store, syncOptions);
|
||||||
|
const routes = {
|
||||||
|
components: App,
|
||||||
|
...createChildRoute({
|
||||||
|
getState() { return store.getState(); }
|
||||||
|
})
|
||||||
|
};
|
||||||
// createRouteProps({
|
// createRouteProps({
|
||||||
// redirect: LocationDescriptor,
|
// redirect: LocationDescriptor,
|
||||||
// history: History,
|
// history: History,
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import Show from './components/Show.jsx';
|
import Show from './components/Show.jsx';
|
||||||
import Map from './components/map/Map.jsx';
|
import ShowMap from './components/map/Map.jsx';
|
||||||
|
|
||||||
export const challenges = {
|
export function challengesRoute() {
|
||||||
|
return {
|
||||||
path: 'challenges(/:dashedName)',
|
path: 'challenges(/:dashedName)',
|
||||||
component: Show,
|
component: Show,
|
||||||
onEnter(nextState, replace) {
|
onEnter(nextState, replace) {
|
||||||
@ -10,14 +11,19 @@ export const challenges = {
|
|||||||
replace('/map');
|
replace('/map');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const modernChallenges = {
|
export function modernChallengesRoute() {
|
||||||
|
return {
|
||||||
path: 'challenges/:block/:dashedName',
|
path: 'challenges/:block/:dashedName',
|
||||||
component: Show
|
component: Show
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const map = {
|
export function mapRoute() {
|
||||||
|
return {
|
||||||
path: 'map',
|
path: 'map',
|
||||||
component: Map
|
component: ShowMap
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
import { modernChallenges, map, challenges } from './challenges';
|
import {
|
||||||
|
modernChallengesRoute,
|
||||||
|
mapRoute,
|
||||||
|
challengesRoute
|
||||||
|
} from './challenges';
|
||||||
import NotFound from '../components/NotFound/index.jsx';
|
import NotFound from '../components/NotFound/index.jsx';
|
||||||
import { addLang } from '../utils/lang';
|
import { addLang } from '../utils/lang';
|
||||||
import settings from './settings';
|
import settingsRoute from './settings';
|
||||||
|
|
||||||
export default {
|
export default function createChildRoute(deps) {
|
||||||
|
return {
|
||||||
path: '/:lang',
|
path: '/:lang',
|
||||||
indexRoute: {
|
indexRoute: {
|
||||||
onEnter(nextState, replace) {
|
onEnter(nextState, replace) {
|
||||||
@ -13,13 +18,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
childRoutes: [
|
childRoutes: [
|
||||||
challenges,
|
challengesRoute(deps),
|
||||||
modernChallenges,
|
modernChallengesRoute(deps),
|
||||||
map,
|
mapRoute(deps),
|
||||||
settings,
|
settingsRoute(deps),
|
||||||
{
|
{
|
||||||
path: '*',
|
path: '*',
|
||||||
component: NotFound
|
component: NotFound
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
@ -1,10 +1,19 @@
|
|||||||
import Settings from './components/Settings.jsx';
|
import Settings from './components/Settings.jsx';
|
||||||
import updateEmail from './routes/update-email';
|
import updateEmailRoute from './routes/update-email';
|
||||||
|
|
||||||
export default {
|
export default function settingsRoute(deps) {
|
||||||
|
const { getState } = deps;
|
||||||
|
return {
|
||||||
path: 'settings',
|
path: 'settings',
|
||||||
component: Settings,
|
component: Settings,
|
||||||
|
onEnter(nextState, replace) {
|
||||||
|
const { app: { user } } = getState();
|
||||||
|
if (!user) {
|
||||||
|
replace('/map');
|
||||||
|
}
|
||||||
|
},
|
||||||
childRoutes: [
|
childRoutes: [
|
||||||
updateEmail
|
updateEmailRoute(deps)
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import UpdateEmail from './Update-Email.jsx';
|
import UpdateEmail from './Update-Email.jsx';
|
||||||
|
|
||||||
export default {
|
export default function updateEmailRoute() {
|
||||||
|
return {
|
||||||
path: 'update-email',
|
path: 'update-email',
|
||||||
component: UpdateEmail
|
component: UpdateEmail
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user