0
I’m trying to configure the routes for my application but when I get official example on github an error of "Maximum Callstack Exceeded"
.
I’ve checked everything point by point and can’t find my mistake.
Just follow my code:
routes.js
'use strict';
import React from 'react';
import auth from './auth';
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
// Global
import AppContainer from '../components/App';
// Login
import LoginForm from '../components/LoginForm';
//Dashboard
import DashboardContainer from '../components/Dashboard';
// Supplier
import SupplierContainer from '../components/Supplier';
import SupplierListContainer from '../components/Supplier/List';
function redirectToLogin(nextState, replace) {
if (!auth.loggedIn()) {
replace({
pathname: '/login',
state: { nextPathName: nextState.location.pathname }
});
}
}
function redirectToDashboard(nextState, replace) {
if (auth.loggedIn()) {
replace('/');
}
}
export const routes = (
<Router history={browserHistory}>
<Route path="/" component={AppContainer}>
<IndexRoute component={DashboardContainer}/>
<Route path="dashboard" component={DashboardContainer} onEnter={redirectToLogin} />
<Route path="supplier" component={SupplierContainer}>
<IndexRoute component={SupplierListContainer}/>
<Route path="list" component={SupplierListContainer}/>
</Route>
<Route path="login" component={LoginForm} onEnter={redirectToDashboard} />
</Route>
</Router>
);
index.js
'use script';
// React
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { store } from './utils/storage/store';
import { routes } from './utils/routes';
render(
<Provider store={store}>
{routes}
</Provider>,
document.getElementById('app')
);
Does anyone have any idea what’s going on?
Thank you in advance
export const routes = (
? this exportsundefined
. Maybe you want toexport default {routes: (
?– Sergio
The strange thing is that he recognizes the routes... the problem happens in the method call
redirectToLogin
which is called several times in a row... I will try to apply your suggestion and see if it helps in something like that. Thank you– Raphael Rosa
Where have you
import {auth} ...
?– Sergio
within the archive itself
routes.js
– Raphael Rosa
Okay, since you’re not (va) in the question I thought it was strange
– Sergio
I edited the import response
– Raphael Rosa
I think you should have
render((<Provider store={store}>
 routes={routes}
 </Provider>),
 document.getElementById('app')
);
in index.js and an object in Routes. You are passing JSX to Routes...– Sergio
also put what you have in auth
– Emir Marques