Skip to content
This repository has been archived by the owner on Sep 11, 2018. It is now read-only.

Issue with nesting the routes #6

Closed
zoilorys opened this issue Aug 8, 2015 · 7 comments
Closed

Issue with nesting the routes #6

zoilorys opened this issue Aug 8, 2015 · 7 comments

Comments

@zoilorys
Copy link

zoilorys commented Aug 8, 2015

Playing around with kit. I got this setup for routes :

<Route component={CoreLayout}>
    <Route name='home' path='/' component={HomeView} />

    <Route name='user-info' path='user' component={UsersView}>
      <Route name='profile' path='user/:id' component={Profile} />
    </Route>
    <Route name='about' path='about' component={AboutView} />

    <Route name='dashboard' path='dashboard' component={DashboardView} />
    <Redirect from='admin' to='dashboard' />
  </Route>

Nested routes like 'user/:id' , or even without params, just 'user/profile' doesn't work - error 404 =\
Tried different types of nesting, even without path with '/', like

<Route name='user-info' path='user' component={UsersView}>
       // this should inherit the route, so its /user/profile
      <Route name='profile' path=profiles' component={Profile} />
</Route>

, nothing works... Read through 1.0.0-beta3 docs many times, it seems like i'm doing everything right - but it doesn't work.
Can anyone figure out whats the problem?
Wrapping component UsersView renders {this.props.children}.

@dvdzkwsk dvdzkwsk added the bug label Aug 8, 2015
@dvdzkwsk
Copy link
Owner

dvdzkwsk commented Aug 8, 2015

Not sure just yet if this is a problem with the starter kit or react-router or some combination, but I've reproduced it and am looking into it.

Going to link to your issue on react-router while this is troubleshooted: remix-run/react-router#1682 ... seems like it might be a problem with their 1.0.0 version, as there are a few related issues open in their repo.

@zoilorys
Copy link
Author

zoilorys commented Aug 8, 2015

@davezuko , yeah i guess so. I think ill try to replace current router with 0.13 and try to work with it until it will be resolved. Thank you :)

@dvdzkwsk dvdzkwsk removed the bug label Aug 8, 2015
@dvdzkwsk
Copy link
Owner

dvdzkwsk commented Aug 8, 2015

@zoilorys Ok, hopefully that works. I experimented with removing the <Provider> that we have to wrap the <Router> in but had no success. I'm not doing anything else special with the routes so I'm pretty convinced it's a bug with react-router, sadly. I'll ping you if I manage to get it working.

Going to leave this ticket open in the meantime in case someone happens to have an idea.

@zoilorys
Copy link
Author

zoilorys commented Aug 8, 2015

@davezuko , ok, thanks again) Yeah i will post here if swapping router version helps, then i guess it will be obvious whats the problem.

@dvdzkwsk
Copy link
Owner

dvdzkwsk commented Aug 8, 2015

@zoilorys I changed the history that's passed to the Router from BrowserHistory to HashHistory and it works... so now on to see why this is the case. But you could use that as an alternative for now.

In the starter-kit, this is in ~/src/entry-points/client.js

This is my route structure

export default (
  <Route component={CoreLayout}>
    <Route name='home' path='/' component={HomeView} />
    <Route name='user' path='/user' component={UserView}>
      <Route path='/:id' component={ProfileView} />
    </Route>
    <Route name='about' path='/about' component={AboutView} />
  </Route>
);

Then:

// views/user/profile/index.jsx
import React from 'react';

export default class ProfileView extends React.Component {
  constructor () {
    super();
  }

  render () {
    return (
      <div>
        <h2>Profile {this.props.params.id}!</h2>
      </div>
    );
  }
}

// views/user/index.jsx
import React from 'react';

export default class UserView extends React.Component {
  constructor () {
    super();
  }

  render () {    
    return (
      <div>
        <h1>User View!</h1>
        {this.props.children}
      </div>
    );
  }
}

@dvdzkwsk
Copy link
Owner

dvdzkwsk commented Aug 8, 2015

Also might want to check this out: remix-run/react-router#676

@dvdzkwsk
Copy link
Owner

dvdzkwsk commented Aug 8, 2015

@zoilorys sorry for the spam lol, but I just added a publicPath option in the webpack client configuration and it appears to have fixed the issue. Either pull the latest master or add it yourself... hopefully this solves your problem!

// ~/build/webpack/client/index.js
const config = makeConfig({
  name   : 'Client',
  target : 'web',
  entry  : {
    app : [
      projectConfig.inSrc('entry-points/client')
    ],
    vendor : projectConfig.VENDOR_DEPENDENCIES
  },
  output : {
    filename : '[name].[hash].js',
    path     : projectConfig.inDist('client'),
    publicPath : '/' // ADD THIS
  }
});

@dvdzkwsk dvdzkwsk closed this as completed Aug 8, 2015
juanda99 referenced this issue in juanda99/react-redux-starter-kit Mar 20, 2016
Merge pull request #4 from davezuko/master
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