【问题标题】:Golang with React Router?Golang 与 React 路由器?
【发布时间】:2015-09-13 22:10:58
【问题描述】:

如何在 Go 中使用 React Router?


例如,

我在 Go 中有这个:

Echo.Get("/*", *handler which return page with ReactRouter*)

这在 React Router 中:

React.render((
<Router history={History.createHistory()}>
    <Route name="index" path="/" component={Main}>
        <Route name="users" path="/users" component={Users}>
            <Route name="user" path="/user/:userId" component={User} />
        </Route>
        <Route path="*" component={NotFound} />
    </Route>
</Router>
), document.body)

但我不断得到索引 (/) 页面。所有路由的行为都相同('/'、'/users'、'/user/qwe' 等)

【问题讨论】:

    标签: go reactjs react-router


    【解决方案1】:

    你必须用新的绑定来渲染不同的路由,或者在你的处理函数中专门处理那个绑定并读出请求对象的信息。

    Echo.Get("/user/:id", getUser)
    Echo.Get("/users", listUsers)
    Echo.Get("/*", catchAllRemainingCalls)
    

    希望这会有所帮助。祝你好运!

    【讨论】:

      猜你喜欢
      • 2018-04-04
      • 1970-01-01
      • 2017-01-03
      • 2017-10-07
      • 2021-03-16
      • 1970-01-01
      • 2020-07-10
      • 2021-05-28
      • 2019-05-30
      相关资源
      最近更新 更多