reactjs - 带有下一个路由器的默认布局(页眉、页脚)
问题描述
我搜索了类似的问题,但最终无法理解如何实现我所需要的。抱歉重复或非常菜鸟的问题。
我正在尝试从 CRA 迁移到 Next,所以我从路线开始。
在 CRA 的 App.js 中,我有:
const DefaultLayout = ({withSlider, component: Component, ...rest}) => {
return (
<Route {...rest} render={matchProps => (
<Fragment>
<Nav withSlider={withSlider}/>
<Component {...matchProps} />
<Footer />
</Fragment>
)} />
)
};
然后我像这样组织应用程序中的所有路线:
<Router>
<Switch>
<DefaultLayout exact path="/" withSlider={true} component={MainPage} />
<DefaultLayout exact path="/people" withSlider={false} component={People} />
<DefaultLayout exact path="/news" withSlider={false} component={News} />
<DefaultLayout exact path="/news/:uid" withSlider={false} component={Article} />
</Switch>
</Router>
所以关于Next的两个问题
- 如何使用参数 withSlider 发送到组件来实现 DefaultLayout?
- 如何将 URL 中的 :uid 参数发送到组件(稍后通过 match.params 获取)?
ps 我知道next-routes,但我认为这个功能非常普遍,以至于它必须以某种方式在 next-router 本身中实现
解决方案
推荐阅读
- flutter - Dart (Flutter) 中的常量构造函数
- xpath - XPath“和”混淆
- linux - ioctl 与 Linux 中的内核模块
- python - Python脚本在anaconda3上运行时不在cmd上运行
- java - 试图创建一个输出所有可能的字母 AD 组合的程序
- java - 为什么 Spring State Machine PersistStateChangeListener 组件有时不在同一线程中执行?
- javascript - reactcodesandbox 不同行为输入不失焦点
- regex - 正则表达式查找不在列表中的单词
- matlab - MATLAB:如何关闭“哔”声?
- reactjs - 每次间隔自动从 api 更新 firebase 数据库