question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router Ignores 3rd level deep paths

See original GitHub issue
    "/foo/bar": {
      component: dynamicWrapper( app, ["unions"], () => import( "../routes/Foo/Bar" ) )
    },
    "/foo/bar/baz": {
      component: dynamicWrapper( app, ["unions"], () => import( "../routes/Foo/Baz" ) )
    },

When going to /foo/bar/baz it does not render. This is because of getRoutes(), getRendererArr() and getRelation() inside /src/utils/utils.js

getRelation() checks on .every on the original renderArr compared to the routes.

With these two comparisions:["foo","bar"] => ["foo","bar","baz"] It does the following:

"foo" === "foo"
"bar" === "bar"
return 2;

It should do the following:

"foo" === "foo"
"bar" === "bar"
undefined === "baz"
return 3;

It doesn’t get to the baz and assumes it’s the same. This is a fundamental problem with the router. Perhaps @chenshuai2144 can give more information since he wrote the code

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
zjxpcyccommented, Feb 25, 2018

@chenshuai2144 我也遇到了这个让人头痛的问题。为什么会加这个东西? 出于什么考虑的呢?

我现在的路由定义方式,有点类型 RESTFUL, 或者 表意的 成分,比如 /articles 代表 列表, /articles/2018-01-01 代表 1 号的文章, 这种 URL 很正常的啊, 但是配置 路由的时候就是 因为你们加的这种规则,不适用了。除非,我要舍弃你们整个的路由架构,或者按照你们的约定来加代码,这两种选择都不是我想做的。

我的理解是,这种约定,有点特殊化,或者说有点过度设计的嫌疑。 建议放开这个限制,或者加一个开关来启用,这样比较好。

0reactions
ddcat1115commented, Feb 27, 2018

@zjxpcyc 脚手架中渲染路由的地方使用了 getRoutes(),这个函数主要就是增加筛选和分析 exact 属性,只是为了方便路由的嵌套渲染,这是目前脚手架中最常见的路由组织模式(比如 a/b 这种路由都是在 a 的内部渲染),如果不需要这种筛选和分析,可以不用 getRoutes,直接拿 routerData 自己处理就行

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-router ignoring nested routes when providing url with path
I'm playing around with the react and redux trying to put together a basic app with react-routes . At the moment I have...
Read more >
possibility to use nested routes with absolute paths ... - GitHub
A nested route with an absolute path that does not exactly match its parent routes' paths is not valid, so any child routes...
Read more >
Ultimate React Router v6 Guide
React Router is by far the most popular routing library in React and this article goes in depth on everything you need to...
Read more >
Troubleshooting Angular routing - Medium
List routes with a static path first, followed by an empty path route, which matches the default route. The wildcard route comes last...
Read more >
Routing in Vue3: Navigating the Options - CODE Magazine
Let's see how routing in Vue 3 works. What is Routing? In many Vue projects, you'd like the ability to navigate to different...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found