【问题标题】:React router, client side rendering (only)React 路由器,客户端渲染(仅限)
【发布时间】:2016-03-29 18:40:41
【问题描述】:

我正在使用 react 路由器浏览我的应用程序,但我不希望 react 路由器调用服务器,这可能吗?

【问题讨论】:

  • 是的 react-router 不与任何服务器接口.. 反应堆栈中的任何内容都不是客户端
  • @azium 在我的应用程序中是这样!
  • 我不明白你的问题是什么..
  • 你是如何过渡路线的?如果直接设置location.href会打到服务器,但是如果使用browserHistory.push()就不会。也就是说,如果您直接点击路线(即输入地址并按回车键)。它会攻击你的服务器。在这种情况下,您需要您的服务器提供index.html。见github.com/reactjs/react-router/blob/master/docs/guides/…

标签: reactjs rendering client-side react-router


【解决方案1】:

你应该使用Hash history

import { Router, Route }  from 'react-router'
import createHashHistory  from 'history/lib/createHashHistory'

<Router history={ createHashHistory({ queryKey: false }) }>
  <Route path="/" component={App} />
</Router>

如果您不想使用哈希历史记录(将# 附加到网址),请使用Link Component,它将根据传递的历史记录类型正确导航应用程序。

【讨论】:

    猜你喜欢
    • 2016-05-26
    • 1970-01-01
    • 2015-09-06
    • 2015-04-19
    • 1970-01-01
    • 2021-08-27
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多