4Catalyzer / 4Catalyzer/found

routeConfig array breaks with nested children, unless an empty object is provided

Open
#657 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
795
Forks
55
Avg merge
5h 5m
Merged PRs (30d)
2

Description

Hi @taion,
I have recently upgraded to found 0.4.9 and bumped into quite an annoying issue.

I suppose most of people create a router by using the JSX route config which still works perfectly fine.
However when using the routeConfig array of objects this no longer works as documented and I'm not able to navigate through routes that have a children.

I noticed that when using the JSX routes, makeRouteConfig will prepend an empty object to all the children routes.
The issue lies here, routeConfig array now expects the empty object to be defined when you have a children; most likely to cater for the scenario where you want to render a component on the children without the need of a subpath; f.i. on the top level route as follow:

const routeConfig = [{ path: '/', Component: AppPage, children: [{ Component: MainPage, }, {...}, {...}] }]

To summarise as per documentation this is how we're supposed to build the routeConfig array of objects:

const routeConfig = [
  {
    path: '/',
    Component: AppPage,
    children: [
      {
        Component: MainPage,
      },
      {
        path: 'foo',
        Component: FooPage,
        children: [
          {
            path: 'bar',
            Component: BarPage,
          },
        ],
      },
    ],
  },
];

However the above won't allow navigation through children whilst instead adding an empty object to the children array will fix this issue; as below:

const routeConfig = [
  {
    path: '/',
    Component: AppPage,
    children: [
      {},
      {
        Component: MainPage,
      },
      {
        path: 'foo',
        Component: FooPage,
        children: [
          {},
          {
            path: 'bar',
            Component: BarPage,
          },
        ],
      },
    ],
  },
];

I believe this wasn't an intentional breaking change as is not documented, and I'm not sure it would make much sense, so should probably be classified as a bug.

Any chance you can issue a patch for this?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing makeRouteConfig, the entry point named in the report, and reproduce the documented routeConfig examples with nested children. Compare the JSX-generated configuration with the array form and verify navigation without manually inserted empty objects; done means nested routes work as documented and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.