Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child routes seem not to work #35

Closed
Dmitry-N-Medvedev opened this issue Jul 12, 2016 · 13 comments · May be fixed by #86
Closed

child routes seem not to work #35

Dmitry-N-Medvedev opened this issue Jul 12, 2016 · 13 comments · May be fixed by #86

Comments

@Dmitry-N-Medvedev
Copy link

Dmitry-N-Medvedev commented Jul 12, 2016

The following code in will never hit the /:cid subpath:

export default {
  path: '/clients',
  action: () => <Clients />,
  children: [
    {
      path: '/:cid',
      action(context) {
        console.log('action /:cid');
        return context.params.cid;
      }
    }
  ]
};
@koistya
Copy link
Member

koistya commented Jul 12, 2016

@Dmitry-N-Medvedev resolve(routes, { path: '/clients/123' })?

@Dmitry-N-Medvedev
Copy link
Author

I'm using react-starter-kit... Do I require to make changes to it to have child routes operational?

@koistya
Copy link
Member

koistya commented Jul 12, 2016

Child routes should work in react-starter-kit out of the box. I will test your use case in RSK..

@boonep
Copy link

boonep commented Aug 8, 2016

Any word on this? I've come across the same issue with RSK. Thanks!

@dreambo8563
Copy link

I got the same issue, children router not working

@chilic
Copy link

chilic commented Aug 25, 2016

I found solution:
Parent route should be like

export default {
  path: '/parent',

  async action({ next }) {
    const component = await next();
    return component;
  },

  children: [
    {
      path: '/', // Same as "/parent"
      action: async () => <ParentComponent />,
    },
    childRoute, // Will be "/parent/child"
  ],
};

@dreambo8563
Copy link

@chilic not working for me:

export default {

  path: '/contact',

  async action() {
    const Contact = await new Promise((resolve) => {
      require.ensure([], (require) => resolve(require('./Contact').default));
    });


    return <Contact />;
  },
  children: [
    {
      path: '/', // Same as /parent
      action: () => <Contact />,
    },
    {
      path: '/contact/name', // Same as /parent
      action: async () => {
        console.log('in name router')
        return <h1>good</h1>
      },
    },
  ],

};

@chilic
Copy link

chilic commented Aug 25, 2016

@dreambo8563
Look at action method:

  async action({ next }) {
    const component = await next();
    return component;
  },

@dreambo8563
Copy link

@chilic you save my world

this works

export default {

  path: '/contact',

  // async action() {
  //   const Contact = await new Promise((resolve) => {
  //     require.ensure([], (require) => resolve(require('./Contact').default));
  //   });


  //   return <Contact />;
  // },
  async action({ next }) {
    const component = await next();
    return component;
  },
  children: [
    {
      path: '/', // Same as /parent
      action: () => <Contact />,
    },
    {
      path: '/name',
      action: async () => {
        console.log('in name router')
        return (
          <div>
            <h1>good</h1>
            <Contact />
          </div>
        )
      },
    },
  ],

};

@frenzzy
Copy link
Member

frenzzy commented Oct 20, 2016

This should be fixed, please reopen if necessary.

@frenzzy frenzzy closed this as completed Oct 20, 2016
@vishwanatharondekar
Copy link

Solution given by @chilic works but this needs to be solved. I guess for this to work, child route must be resolved before parent route, when both child and parent routes are available.

@frenzzy
Copy link
Member

frenzzy commented Oct 29, 2016

The right way here is:

const routes = {
  path: '/users', // base url
  children: [
    {
      path: '/', // main page
      action() { return 'User List' }
    },
    {
      path: '/:id', // child page
      action(context) { return `User #${context.params.id}` }
    },
  ]
};

Playground: https://jsfiddle.net/frenzzy/o50uu79q/

@vishwanatharondekar
Copy link

vishwanatharondekar commented Oct 30, 2016

@frenzzy Above solution given works as expected. It will be great if we could get a warning that children route and parent action are available together. Easy to do this mistake for user of the router.

@frenzzy frenzzy mentioned this issue Mar 29, 2017
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants