反应路由器4 - 链接到页面外反应应用程序

时间:2017-11-12 20:33:34

标签: node.js reactjs express react-router passport.js

我正在构建一个使用护照的facebook身份验证的节点+反应应用程序。使此身份验证工作涉及到达快速路线' / auth / facebook'。不幸的是,一旦反应应用程序加载反应路由器4不允许链接直接命中快递服务器而是搜索匹配' auth / facebook'的反应路由。简而言之,在使用反应路由器4时,如何链接到我的应用程序中的路由但在反应应用程序之外?

1 个答案:

答案 0 :(得分:0)

React Router is only for client side routing. Use fetch API or a similar library for that.

I'll state one way of solving your problem (using fetch and without react router).

  1. Remove the href from the <a> tag
  2. Add an event listener for the click event, <a onClick={makeCall}>

Then in the makeCall function, you can call the backend using the fetch API(or axios or whatever),

makeCall() {
    fetch('/auth/facebook', options)
        .then((res) => {
            // Something 
        })
        .catch((err) => {
            // handle error
        });
}
相关问题