मेरे पास एक उच्च ऑर्डर घटक है जो जांचता है कि कोई उपयोगकर्ता प्रमाणीकृत है और यदि नहीं, तो एक अलग यूआरएल पर रीडायरेक्ट होगा।प्रतिक्रिया राउटर सर्वर पर रीडायरेक्ट नहीं कर रहा है
इसका एक आइसोमोर्फिक ऐप है और यह क्लाइंट-साइड काम करता है लेकिन अगर मैं जेएस बंद कर देता हूं, तो सर्वर रीडायरेक्ट नहीं करता है।
if (!this.props.authenticated) {
this.context.router.push('/');
}
मैं सर्वर पर इस बयान हिट कर सकते हैं और this.context.router
लौट रहा है, लेकिन कुछ नहीं होता।
पूर्ण घटक:
export default (
<Route path='/' component={App}>
<IndexRoute component={Welcome} />
<Route path='/feature' component={requireAuth(Feature)} />
<Route path='/signin' component={Signin} />
<Route path='/signout' component={Signout} />
<Route path='/signup' component={Signup} />
</Route>
);
इस सर्वर प्रस्तुत करना है कोड:
import { RouterContext, match } from 'react-router';
import { Provider } from 'react-redux';
import { renderToString } from 'react-dom/server';
import React from 'react';
import reactCookie from 'react-cookie';
import configureStore from '../../shared/store';
import routes from '../../shared/routes';
import assets from '../../public/assets.json';
import { AUTH_USER } from '../../shared/actions/types';
export default function (req, res) {
match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
if (error) return res.status(500).send(error.message);
if (redirectLocation) return res.redirect(302, redirectLocation.pathname + redirectLocation.search);
if (!renderProps) return res.status(404).send('Page not found');
const store = configureStore();
// use cookies to retrieve token
const unplug = reactCookie.plugToRequest(req, res); // eslint-disable-line no-unused-vars
const token = reactCookie.load('token');
// if we have a token, consider the user to be signed in
if (token) {
// we need to update application state
store.dispatch({ type: AUTH_USER });
}
const content = renderToString(
<Provider store={store}>
<RouterContext {...renderProps} />
</Provider>
);
const initialState = JSON.stringify(store.getState());
return res.render('index', { content, assets, initialState });
});
}
आपने जेएस "ऑफ" चालू कर दिया है। आप इसे कैसे काम करने की उम्मीद करते हैं? – activatedgeek
यह एक isomorphic ऐप node.js – Paul