反应路由器 v1.0.0 中的 Router.create

编程入门 行业动态 更新时间:2024-10-19 00:29:08
本文介绍了反应路由器 v1.0.0 中的 Router.create的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 react-router v1.0 中 Router.create (react-router v0.13) 的等价物是什么?

What is the equivalent of Router.create (react-router v0.13) in react-router v1.0?

var router = Router.create({ routes: routes, location: null // Router.HistoryLocation });

我想为要在 DOM 之外使用的路由器创建一个引用.

I want to create a reference for the router to be used outside of the DOM.

router.transitionTo('app');

上面的代码片段是 v0.13 中的代码片段.想知道是否有人知道如何在 react-router v1.0 中编写它们.

The code snippet above is the ones in v0.13. Wondering if anyone knows how to write them in react-router v1.0.

我已经浏览了 react-router 的文档,我找到了 createRoutes 函数.我不知道如何使用它.请帮我解决这个问题.

I have gone through the documentation of react-router, and I had found the createRoutes function. I had no idea how to use it. Please help me on this.

推荐答案

从 v1.0 开始,React Router 现在比这更加模块化.导航之类的东西是历史"对象的功能,而不是路由器本身,它只处理路由.

React Router as of v1.0 is now more modular than that. Things like navigation are functions of a "history" object rather than the router itself, which only handles routing.

要使用 React Router v1.0 执行等效操作,您可以在路由器外部实例化 history 对象,然后用它做任何您想做的事情.在组件外部导航指南中提供了更详细的文档:github/rackt/react-router/blob/master/docs/guides/advanced/NavigatingOutsideOfComponents.md.

To do the equivalent with React Router v1.0, you would instantiate the history object outside the router, then do whatever you want with it. There's more detailed documentation available at the guide for navigating outside of components: github/rackt/react-router/blob/master/docs/guides/advanced/NavigatingOutsideOfComponents.md.

更多推荐

反应路由器 v1.0.0 中的 Router.create

本文发布于:2023-11-15 03:58:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1590938.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由器   Router   create

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!