React-Router onChange hook

前端 未结 2 1151
情书的邮戳
情书的邮戳 2021-02-08 03:34

I am having issues getting the onChange hook in react-router to work properly. Here is my routes file:

import React from \'react\';
import { Router, Route, brows         


        
相关标签:
2条回答
  • 2021-02-08 04:11

    onUpdate needs to be declared on the Router instance not Routes. Although, Routes can declare onChange and onEnter hooks - it's probably what you were looking for.

    0 讨论(0)
  • 2021-02-08 04:11

    I'm using react-router ^2.4.0 and onUpdate did not work for me. I have instead used onChange on my base Route component.

    const Routes = (
        <Router history={browserHistory}>
            {/* App Routes */}
            <Route path="/" component={App} lang={lang} onChange={logUpdate}>
                <Route path="/testone" component={TestOne} />
                <Route path="/testtwo" component={TestTwo} />
            </Route>
        </Router>);
    
    0 讨论(0)
提交回复
热议问题