-
Notifications
You must be signed in to change notification settings - Fork 382
约定式路由模式下如何获取所有路由? #6188
-
使用约定式路由模式后,如何获取所有路由信息?在中后台中需要渲染路由菜单,现在是否提供了获取全部路由的api?
是否有import.meta.glob的平替?打包方式为Rspack
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 4 comments 3 replies
-
我的需求是这样,做个子应用模板,上手就写业务,根据路由生成菜单,嵌套主应用时只有路由部分的内容。
如果不要约定路由,这个框架也没必要用了。
之前看文档还是测试好像看到过有获取到约定下的所有路由,有点忘了,后面测试到再研究一下。
Beta Was this translation helpful? Give feedback.
All reactions
-
同样需要获取到全部路由,大佬们有什么好办法没有?
Beta Was this translation helpful? Give feedback.
All reactions
-
目前没有办法获取到,我们会在近期提供这个能力 @ibyxz @lanmingle @shen774411223d
Beta Was this translation helpful? Give feedback.
All reactions
-
目前没有办法获取到,我们会在近期提供这个能力 @ibyxz @lanmingle @shen774411223d
@zllkjc 那大概在那个版本提供该功能?
Beta Was this translation helpful? Give feedback.
All reactions
-
目前已经合入主分支,本周发版,大家可以看看是否能满足需求。
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
@zllkjc 麻烦问一下这边为什么获取不到路由啊?
刚初始化的仓
image
import { useRuntimeContext } from '@modern-js/runtime'; import { useEffect } from 'react'; export default () => { const { routes } = useRuntimeContext(); useEffect(() => { console.log(routes?.map(r => r.path)); }, [routes]); return <h1>Profile</h1>; };
output:
['/', '*']
expected:
e.g. ['/', 'profile', 'item', '*']
version:
"@modern-js/app-tools": "2.67.10"
Beta Was this translation helpful? Give feedback.
All reactions
-
嗯,这里不是一个平铺的结构,是一个嵌套的结构。例如外层的 layout 其实是一层路由,而 item 和 profile 是下一层路由,这个结构是 React Router 吐出的,我们暂时没有将这个结构格式化或平铺。你可以在控制台输出它看一下,每一层都有一个 children 字段,可以自行遍历。
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2