Manu
Manu

Reputation: 1662

Setting up react router

I am trying to set up routing for a simple one page application. When I say one page, I mean that all my components will be rendered at once. My aim with routing was to use it for link to anchor (clicking on the nav will scroll you to the correct section/component).

index.js

No compiling errors but nothing gets rendered and I'm getting the following in my browser console.

browser console

App.js updated

routes.js

I've reverted my App.js to its initial form when it was only rendering the components and working fine. Instead, I've created a separate file, routes.js to hold my routing. If this is correct, how can I get both rendered by my index.js. Or is this not the way things should work?

Upvotes: 1

Views: 304

Answers (1)

Stefan Dragnev
Stefan Dragnev

Reputation: 14473

Router is not the default export of react-router. This is the correct require:

const Router = require('react-router').Router;

You're also not supposed to return a Router from a render() method. A <Router> must be passed directly to ReactDOM.render().

Upvotes: 3

Related Questions