首页 > 解决方案 > react-router 内联渲染道具(Auth0 回调)

问题描述

使用 react-router v2.4.0 并尝试将 Auth0 的回调路由到 Auth0 指定的特定函数和组件。

这是我的路由器代码。没有发生任何事情,似乎不支持 props 或 {location}。我成功进行内联渲染的唯一方法是简单地设置一个 render={myTest()} 路由。但是一直无法获取和传递 props 参数或任何东西。

是因为我使用的是 react-router v2.4.0 吗?不确定我是否已准备好进行 v4 迁移,因为现在这样做可能会花费我相当长的时间。

任何想法?

import Auth from './users/authv9/Auth';
import Callback from './users/authv9/Callback';

const auth = new Auth();
const handleAuthentication = ({location}) => {

    console.log('handleAuthentication #1');
    console.log(location);

    if (/access_token|id_token|error/.test(location.hash)) {

        console.log('handleAuthentication #2');
        auth.handleAuthentication();
    }
}

ReactDOM.render((
    <Router history={browserHistory}>
        <Route path="/" component={App} auth={auth}>

            <IndexRoute component={Home} />

            <Route path="callback" render={(props) => {
                handleAuthentication(props);
                <Callback {...props} /> 
            }}/>

标签: react-routerrenderinlineauth0

解决方案


也许试试

 path="/callback"

如果不是,很可能与使用 v2 而不是 v4 有关


推荐阅读