2016-01-14 11 views
8

में replaceState का उपयोग कर प्रतिक्रिया रूटर 1.0.3 के लिए प्रमाणन प्रवाह उदाहरण का पालन करना मैं कर दिया गया है है/प्रवेश पृष्ठ दिखा अपेक्षा के अनुरूप निष्पादित, लेकिन राज्य:this.props.location.state अशक्त जब onEnter

{ nextPathname: nextState.location.pathname }

कौन सा this.props.location.state में माना जाता है कहीं नहीं पाया जा सकता है। इसके बजाय this.props.location.state अपरिभाषित है।

यह रूप में एक ही मुद्दा हो रहा है: https://github.com/rackt/react-router/issues/2768

किसी को पता होगा क्यों राज्य नहीं किया जा रहा है?

संपादित करें मैंने यह कोशिश की .props.history.replaceState और कोई समस्या नहीं होने पर राज्य को गुजर रहा है। यह केवल तब काम नहीं करता जब ऑनर हुक में।

संपादित 2 प्रयोग और अधिक प्रतिक्रिया के बारे में सीखने के बाद, मुझे एहसास हुआ कि मैं प्रतिक्रिया के साथ प्रतिपादन सर्वर साइड कर रहा था। replaceState समारोह सर्वर में से निकाल देते थे, और Router.match समारोह (सर्वर साइड प्रतिपादन के लिए अनुशंसित) से निकाल देते थे:

Router.match({ routes: routes.default, location: req.url }, function(err, redirectLocation, renderProps) { 
     if (err) { 
      res.status(500).send(err.message) 
     } else if (redirectLocation) { 
      res.status(302).redirect(redirectLocation.pathname + redirectLocation.search) 
     } else if (renderProps) { 
      var html = ReactDOM.renderToString(React.createElement(Router.RoutingContext, renderProps)); 
      var page = swig.renderFile('views/index.html', { html: html }); 
      res.status(200).send(page); 
     } else { 
     res.status(404).send('Page Not Found') 
    } 
    }); 

redirectLocation '/ लॉगिन' के लिए निर्धारित किया जाएगा, और renderProps अगले होते हैं राज्य। लेकिन जाहिरा तौर पर जब एक सर्वर साइड रीडायरेक्ट कर रही है, nextState दिखाई नहीं जाती:

res.status(302).redirect(redirectLocation.pathname + redirectLocation.search)

यदि यह सही है तो सवाल यह है कि एक राज्य जब सर्वर साइड पुन: निर्देशित स्थापित करने के लिए है।

उत्तर

0

घटक में। PathName इस.props.location.pathname में है, मुझे वहां मिला।

_handleSubmit: function(e) { 
    e.preventDefault(); 
    //console.log(this.props.location.state); // null ??? 
    //the above should be changed to 
    console.log(this.props.location.pathname); 
    return false; 
} 
+0

आपके उत्तर के लिए धन्यवाद। मैंने जांच की और मुझे अगले चरण पथनाम के बजाय पथनाम '/ लॉगिन' मिलता है जिसमें मैं सफल लॉगिन के बाद रीडायरेक्ट करना चाहता हूं। क्या आपको एक अलग परिणाम मिलता है? – ieldanr

संबंधित मुद्दे