dongwei5794
2015-09-13 22:10
浏览 111
已采纳

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 2015-09-13 22:17
    已采纳

    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!

    打赏 评论

相关推荐 更多相似问题