0
以下のコードでは、認証されていない場合はreplace pathname
とログインするようにリダイレクトされますが、state
は何をしていますか?次の経路名は、反応ルータのonEnterとは何ですか?
EDITEDフォーカス取得時に同じ場所にユーザーをリダイレクトしない
login.js
login() {
/* ref.authWithOAuthPopup(this.props.provider, (error, authData) => {
if (error) {
console.log("Authentication Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
console.log(this.state) // return null here
}
}) */
}
authenticated.js
import Firebase from 'firebase';
import GLOBAL from './global.js';
var ref = new Firebase(GLOBAL.FIREBASE_URL);
export function requireAuth(nextState, replace) {
ref.onAuth((authData) => {
if (!authData) {
replace ({
pathname: '/login',
state: { nextPathname: nextState.location.pathname }
})
}
})
}
route.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, browserHistory, hashHistory, IndexRoute } from 'react-router';
import Layout from './pages/Layout';
import Purchased from './pages/Purchased';
import Home from './pages/Home';
import Profile from './pages/Profile';
import PurchasedItemDetail from './pages/PurchasedItemDetail';
import Login from './pages/Login';
import { requireAuth } from './utils/authenticated';
ReactDOM.render((
<Router history={browserHistory}>
<Route path="/" component={Layout}>
<IndexRoute component={Home} onEnter={requireAuth} />
<Route path="/login" component={Login} />
<Route path="/purchased" component={Purchased} onEnter={requireAuth} />
<Route path="/purchased/:purchasedItemID" component={PurchasedItemDetail} onEnter={requireAuth} />
<Route path="/profile" component={Profile} onEnter={requireAuth} />
</Route>
</Router>
), document.getElementById('app'))
私はそれを取得しません。ログインコールバックで 'this.state.nextPathname'を呼びますか? – vzhen
私はそれがどのように使用されているかを見なければならないでしょう。 –
my/loginとは異なるファイルにあります –
vzhen