0

I have used create-react-app to start my project.

I have set my index.html div id to wrapper, and at an index.js I am doing getElementById('wrapper').

I am not getting any Errors. I am only getting a warning that refers to IndexRoute saying: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

How can I get my pages to display?

The repo is here:

https://github.com/yarnball/ReactAuthToken

/index.js

ReactDOM.render(
  <BrowserRouter store={store}>
    <Route routes={routes} onUpdate={logPageView} />
  </BrowserRouter>,
  document.getElementById('wrapper')
);

/routes.js

export default (
  <Route path="/" component={App}>
    <IndexRoute component={HomePage} />
    <Route path="register" component={Register} />
    <Route path="login" component={Login} />
    <Route path="logout" component={Logout} />
    <Route path="forgot-password" component={ForgotPassword} />
    <Route path="reset-password/:resetToken" component={ResetPassword} />
    <Route path="dashboard">
      <IndexRoute component={RequireAuth(Dashboard)} />
      </Route>

    <Route path="*" component={NotFoundPage} />
  </Route>
);
2
  • Your react router version? Commented May 18, 2017 at 2:49
  • v4, but 2.6.0 is the same Commented May 18, 2017 at 3:03

1 Answer 1

1

Try following changes

index.js

import { Provider } from 'react-redux';
import Routes from './routes';

...    

ReactDOM.render(
  <Routes store={store} />,
  document.getElementById('wrapper')
);

routes.js

import { BrowserRouter, Route } from 'react-router-dom';

...

export default (props) => (
  <BrowserRouter>
    <Provider store={props.store}>
      <div>
        <Route path="/" component={App} />
        <Route path="register" component={Register} />
        <Route path="login" component={Login} />
        <Route path="logout" component={Logout} />
        <Route path="forgot-password" component={ForgotPassword} />
        <Route path="reset-password/:resetToken" component={ResetPassword} />
        <Route path="*" component={NotFoundPage} />
      </div>
    </Provider>
  </BrowserRouter>
);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I tested it out but looks like it might be related to versioning of it after all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.