如何在react-router-4中集成auth0和hash路由器.....?

时间:2018-05-16 14:19:42

标签: javascript reactjs callback react-router auth0

当我使用浏览器路由实现此代码时,它可以很好地工作,但是当我使用散列路由使用相同的代码时,它将无法工作。

import React from 'react';
import { Route,Router } from 'react-router-dom';
import App from './App';
import Home from './Home/Home';
import Callback from './Callback/Callback';
import Auth from './Auth/Auth';
import history from './history';

const auth = new Auth();

const handleAuthentication = ({location}) => {
  if (/access_token|id_token|error/.test(location.hash)) {
    auth.handleAuthentication();
  }
}

export const makeMainRoutes = () => {
  return (
      <Router history={history}>
        <div>
          <Route path="/" render={(props) => <App auth={auth} {...props} />} />
          <Route path="/home" render={(props) => <Home auth={auth} {...props} />} />
          <Route path="/callback" render={(props) => {
            handleAuthentication(props);
            return <Callback {...props} /> 
          }}/>
        </div>
      </Router>
  );
}

参考:Auth0 React Login

0 个答案:

没有答案