Closed ndrean closed 3 years ago
You are seeng the errors because you are actually trying to render <NavNext>{{ redirect: "" }}</NavNext>
which is not allowed in React.js.
The "next" function of a middleware action gets a child route result as is:
- const component = await next(true);
+ const component = { redirect: "" };
We have some docs about redirects here: https://github.com/kriasoft/universal-router/blob/master/docs/redirects.md
Ah thks, yes stupid! I did not look at what component looked like...
const component = await next(true);
if (component.redirect) { return component; }
return component && <NavNext>{component}</NavNext>; },
works because I add condition in router.resolve. Thks for the help. Le samedi 19 décembre 2020 à 22:13:03 UTC+1, Vladimir Kutepov notifications@github.com a écrit :
You are seeng the errors because you are actually trying to render
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
I'm submitting a ... bug?
Notes:
Please do not use the issue tracker for personal support requests (use Gitter, HackHands or Codementor).
Please do not derail or troll issues. Keep the discussion on topic and respect the opinions of others.
Please do not open issues or pull requests regarding the code in
path-to-regexp
(open them in their respective repositories).Bug reports
A bug is a demonstrable problem that is caused by the code in the repository. Good bug reports are extremely helpful - thank you!
Guidelines for bug reports:
DONE
Check if the issue has been fixed — try to reproduce it using the latest
master
or development branch in the repository.Isolate the problem — ideally create a reduced test case and a live example.
A good bug report shouldn't leave others needing to chase you up for more information. Please try to be as detailed as possible in your report. What is your environment? What steps will reproduce the issue? What browser(s) and OS experience the problem? What would you expect to be the outcome? All these details will help people to fix any potential bugs.
Example:
I include the example: https://stackblitz.com/edit/demo-universal-router-react
I use your middleware approach with "context.next" to build the routes. In this manner, I can't redirect. To see this: select the "routeNext" in the "renderRoute" method, and choose "mode:A" for redirection, and anything else if not. This fails. I included the "good" example of redirection without "next". For this, choose "route" in the renderRoute, and you can play with the "mode:A" for redirecting or not. Not sure of what the parser does with the condition "if (true) return {redirect: "/"}". It seems to only append the key "redirect" but does not replace them all. The error message you get is: "Objects are not valid as a React child (found: object with keys {redirect})"
Feature requests
Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible.