4Catalyzer / 4Catalyzer/found

<Redirect> broken with nested routes

Open
#786 1 comment 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

We use nested routes throughout to better handle things with found-relay and just general organization improvements. A sample URL is /organizations/:organizationId/parameters. I tried to redirect from /organizations/:organizationId/dataStore to /organizations/:organizationId/parameters with:

<Redirect from="dataStore" to="parameters" status={301} />
<Route path="parameters">
   ...
</Route>

I can show the full hierarchy if needed, but hopefully you can see that the path field here corresponds to the last part of the URL. The issue is, this semi-redirects. The URL will be replaced with the correct one, but a 404 HttpError will also be thrown. It's a bit tricky to trace through, but I can see the initial RedirectException is thrown, but is subsequently rewritten to a 404 HttpError because resolveRenderArgs is unable to find a match for the rewritten match:

https://github.com/4Catalyzer/found/blob/5d790f49afb38a434aff3ee112ed166a2977737f/src/resolveRenderArgs.js#L33-L46

As far as I can tell, the problem here is because the original match object doesn't contain the full path of the match, only the local path from the nested route. This causes routes to be null and consequently, the 404 HttpError is thrown. Elsewhere, the redirect seems to go through and rewrite the URL, leading to an overall confusing situation.

I found that if I treated the redirect as a flat route, that things worked:

<Redirect from="/organizations/:organizationId/dataStore" to="/organizations/:organizationId/parameters" status={301} />

I'm happy to have a solution, but it'd be nice if we could make use of our existing nesting structure. Alternatively, if nested redirects are not supported, it'd be helpful to have a runtime error that fails entirely. The current half-working, half-failing case makes it unclear what the problem is.

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 reading src/resolveRenderArgs.js at the linked lines and reproduce the nested Redirect from the issue. Trace how the local match is rewritten and why routes becomes null; done means nested redirects no longer produce a 404, or unsupported nested redirects fail entirely with a clear runtime error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.