React Router won't render any other routes

881 Views Asked by At

I'm on the latest version of React, React-router, React-router-redux, and react-redux but I can't seem to get any other routes other than my App to render. All I get is a blank page. I'm not doing any nesting, but I suspect it might have to do with my setup... also no errors crop up when examining in console.

my index.js looks like this:

import 'babel-polyfill';
// Write entry-point js for webpack here....
import React from 'react';
import {render} from 'react-dom';
import {Provider} from 'react-redux';
import App from './containers/App';
import configureStore from './store/configureStore'
import { Router, Route, browserHistory } from 'react-router';
import { PasswordResetView } from './views/PasswordResetView';
import {Test} from './components/Test';

const store = configureStore()

const reactEntry = document.getElementById('react-root');
// Render....
render(
<Provider store={store}>
  <Router history={browserHistory}>
    <Route path="/" component={App}/>
    <Route path="/test" component={Test}/>
  </Router>
</Provider>,
  reactEntry
)

my App.js is this:

import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { loginUser } from '../../actions';
import Navbar from '../../components/Navbar';
import {Link} from 'react-router';

class App extends Component {
  render() {
    const { dispatch, isAuthenticated, errorMessage, isFetching } =             this.props
return(
  <div>
    <div>
      <Navbar
        isFetching={isFetching}
        isAuthenticated={isAuthenticated}
        errorMessage={errorMessage}
        dispatch={dispatch}/>
    </div>
    {this.props.children}
    <div>
      <Link to="/test">Test</Link>
    </div>
  </div>
)
  }
}

App.propTypes = {
  dispatch: PropTypes.func.isRequired,
  isFetching: PropTypes.bool.isRequired,
  isAuthenticated: PropTypes.bool.isRequired,
  errorMessage: PropTypes.string
}

const mapStateToProps = (state) => {
  const { isAuthenticated, errorMessage, isFetching } = state.auth
  console.log(state.auth)

  return {
    isAuthenticated,
    errorMessage,
    isFetching
  }
}

export default connect(mapStateToProps)(App)

My Test.js file import React, {Component} from 'react'

export default class Test extends Component {
  render(){
    return (
      <div>Test</div>
    )
  }
}

Any help whatsoever would be much appreciated!! I'm sure I've screwed something up somewhere...

1

There are 1 best solutions below

0
On

I ended up rewriting my App component as more of a home/parent component to house my other routes. I'm guessing I was misusing react-router and had some sort of problem rendering between child and parent routes (although I did use this.props.children to test that.. who knows!)

render(
  <Provider store={store}>
    <Router history={browserHistory}>
      <Route path="/" component={App}/>
      <Route path="/register(/:token)" component={RegistrationCompleteView}/>
      <Route path="/resend-confirmation" component={ResendConfirmationView}/>
      <Route path="/password-reset" component={PasswordRequestView}/>
      <Route path="/password-reset(/:token)" component={PasswordCompleteView}/>
      <Route path="/login" component={LoginView}/>
    </Router>
  </Provider>,
  reactEntry