Skip to content

Instantly share code, notes, and snippets.

@dmitrylebedev
Created April 17, 2017 20:32
Show Gist options
  • Save dmitrylebedev/12c1eb7d3903ac06f1f397c99b448a7e to your computer and use it in GitHub Desktop.
Save dmitrylebedev/12c1eb7d3903ac06f1f397c99b448a7e to your computer and use it in GitHub Desktop.
display a 404 and keep the path
// THE QUESTION: How could I display a 404 page and keep the path in case '/games/wrong-id'.
// ------------------------------------------------------------------
// ROUTES CONFIG
// ------------------------------------------------------------------
import * as auth from './helpers/authenticationHelper';
import React from 'react';
import {
Route,
IndexRoute
} from 'react-router';
/**
* @see https://github.com/ReactTraining/react-router/blob/v3/docs/API.md#onenternextstate-replace-callback
*
* @param {Object} netState
* @param {Function} replace
* @param {Function} next
*/
const redirectForGame = (netState, replace, next) => {
if (!auth.isLoggedIn()) {
replace('/auth/enter');
next();
}
next();
}
export default (
<Route path="/" component={App}>
<IndexRoute
component={LessonsContainer}
/>
<Route
path="/games/:id_game"
component={GameContainer}
onEnter={redirectForGame}
/>
<Route path="*" component={Page404} />
</Route>
);
// ------------------------------------------------------------------
// AJAX CONFIG
// ------------------------------------------------------------------
import axios from 'axios';
import { browserHistory } from 'react-router';
export const ajax = axios.create({
headers: {
'Content-Type': 'application/json'
},
timeout: 2000,
transformRequest: [
(data) => {
return JSON.stringify(data);
}
],
validateStatus: function(status) {
if (status === 404) {
// browserHistory.replace(`${window.location.pathname}`)
}
//if (status >= 500 && status < 600) ;
//if (status === 401) return true;
return status >= 200 && status < 300; // default
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment