Fix(routes): user sensitive routes redirect to map

This commit is contained in:
Berkeley Martinez
2016-08-12 15:28:05 -07:00
parent 8addca59de
commit 053e5e385e
5 changed files with 82 additions and 56 deletions

View File

@ -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,

View File

@ -1,23 +1,29 @@
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() {
path: 'challenges(/:dashedName)', return {
component: Show, path: 'challenges(/:dashedName)',
onEnter(nextState, replace) { component: Show,
// redirect /challenges to /map onEnter(nextState, replace) {
if (nextState.location.pathname === '/challenges') { // redirect /challenges to /map
replace('/map'); if (nextState.location.pathname === '/challenges') {
replace('/map');
}
} }
} };
}; }
export const modernChallenges = { export function modernChallengesRoute() {
path: 'challenges/:block/:dashedName', return {
component: Show path: 'challenges/:block/:dashedName',
}; component: Show
};
}
export const map = { export function mapRoute() {
path: 'map', return {
component: Map path: 'map',
}; component: ShowMap
};
}

View File

@ -1,25 +1,31 @@
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) {
path: '/:lang', return {
indexRoute: { path: '/:lang',
onEnter(nextState, replace) { indexRoute: {
const { lang } = nextState.params; onEnter(nextState, replace) {
const { pathname } = nextState.location; const { lang } = nextState.params;
replace(addLang(pathname, lang)); const { pathname } = nextState.location;
} replace(addLang(pathname, lang));
}, }
childRoutes: [ },
challenges, childRoutes: [
modernChallenges, challengesRoute(deps),
map, modernChallengesRoute(deps),
settings, mapRoute(deps),
{ settingsRoute(deps),
path: '*', {
component: NotFound path: '*',
} component: NotFound
] }
}; ]
};
}

View File

@ -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) {
path: 'settings', const { getState } = deps;
component: Settings, return {
childRoutes: [ path: 'settings',
updateEmail component: Settings,
] onEnter(nextState, replace) {
}; const { app: { user } } = getState();
if (!user) {
replace('/map');
}
},
childRoutes: [
updateEmailRoute(deps)
]
};
}

View File

@ -1,6 +1,8 @@
import UpdateEmail from './Update-Email.jsx'; import UpdateEmail from './Update-Email.jsx';
export default { export default function updateEmailRoute() {
path: 'update-email', return {
component: UpdateEmail path: 'update-email',
}; component: UpdateEmail
};
}