React-router: Maximum Callstack Exceeded

Asked

Viewed 53 times

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 exports undefined. Maybe you want to export default {routes: ( ?

  • 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

  • Where have you import {auth} ... ?

  • within the archive itself routes.js

  • Okay, since you’re not (va) in the question I thought it was strange

  • I edited the import response

  • I think you should have render((<Provider store={store}>&#xA; routes={routes}&#xA; </Provider>),&#xA; document.getElementById('app')&#xA;); in index.js and an object in Routes. You are passing JSX to Routes...

  • also put what you have in auth

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.