Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Ask Please!! nested Router gives Warnings, but still working #297

Open
vianhanif opened this issue Mar 2, 2017 · 1 comment
Open

Ask Please!! nested Router gives Warnings, but still working #297

vianhanif opened this issue Mar 2, 2017 · 1 comment

Comments

@vianhanif
Copy link

vianhanif commented Mar 2, 2017

Hi there... I am still new with routing in react. Just wanna ask. am i doing this right?
So I have some features that each one has their own CRUD urls (like to see list, create new item, etc). But I am trying to seperate each feature to have its own main routes. So here's what I did to do it:

here's how i create url routes for feature called 'user' and 'member'

  1. user-routes.jsx
import React, { Component } from 'react';
import {Router, Route, browserHistory, hashHistory} from 'react-router'
import {User} from 'pages'

class UserRoutes extends Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
          <Router history={browserHistory}>
            <Route path="/users" component={User.Home}/>
          </Router>
        );
    }
}

export default UserRoutes;
  1. member-routes.jsx
import React, { Component } from 'react';
import {Router, Route, browserHistory, hashHistory} from 'react-router'
import {Member} from 'pages'

class MemberRoutes extends Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
          <Router history={browserHistory}>
            <Route path="/members" component={Member.Home}/>
          </Router>
        );
    }
}

export default MemberRoutes;

and I create a main route to combine those routes with this
3. main-route.jsx

import React, { Component } from 'react';
import {Router, Route, browserHistory} from 'react-router'
import {ContainerApp} from 'containers'
import {
  MemberRoutes,
  UserRoutes
} from './apps/_routes'

class MainRoute extends Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <Router history={browserHistory}>
              <Route path="/" component={ContainerApp}>
                <Route path="/members" component={MemberRoutes}/>
                <Route path="/users" component={UserRoutes}/>
              </Route>
            </Router>
        );
    }
}

export default MainRoute;

And every time I click a link, it will be handled from the main-route, but it keeps giving this error whenever I click the links

I still thinks it won't harm me any further, but I can't ignore it.
Any response would be really great~

@ghostsquad
Copy link

You only need the router at the top level. Keep the routes in the sub-components, just remove the router.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants