反应路由器 v1.0.0 中的 Router.create [英] Router.create in react-router v1.0.0

查看:44
本文介绍了反应路由器 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 对象,然后用它做任何您想做的事情.在组件外部导航指南中提供了更详细的文档:https://github.com/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: https://github.com/rackt/react-router/blob/master/docs/guides/advanced/NavigatingOutsideOfComponents.md.

这篇关于反应路由器 v1.0.0 中的 Router.create的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆