dongwei5794
dongwei5794
2015-09-13 22:10

Golang和React Router?

已采纳

How do I use React Router with Go?


For example,

I have this in Go:

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

And this in 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)

But I keep getting the index (/) page. All routes behave the same ('/', '/users', '/user/qwe', etc.)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dqt66847 dqt66847 6年前

    You have to render different routes with new bindings, or handle that binding specifically in your handler function and read out the request object's information.

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

    Hope this helps. Good luck!

    点赞 评论 复制链接分享