2016-09-08 6 views
0

私はハイブリッドreact/angularjsアプリケーションを持っています。反応に存在しないルートにルーティングするときは、サーバーが角ページを返すように全ページをリロードする必要があります。エラーがスローされるのがわかりますWarning: [react-router] Location '/foo-bar' did not match any routes。どのように私はそれを傍受し、全ページをリロードすることができますか?キャッチ「警告:[react-router]場所 '/ foo-bar'がどのルートとも一致しませんでした」

答えて

1

が、これは

// From the react-router docs: "If `callback` is listed as a 3rd argument, 
// this hook will run asynchronously, and the transition will block 
// until `callback` is called." 
const reloadPage = (nextState, replace, callback) => { 
    window.location.reload(); 
}; 

const routes = (
    <Route path="/" component={Chrome}> 
    <IndexRoute component={Home}/> 
    <Route path="catagory" component={CategoryPage}/> 
    <Route path="*" onEnter={reloadPage}/> 
    </Route> 
); 

ReactDOM.render((
    <Router history={browserHistory}>{routes}</Router> 
), 
    rootEl 
); 
なり... react-router v3の

const reloadPage = (nextState, replace, callback) => { 
    callback("Route not found"); 
    window.location.reload(); 
}; 

const routes = (
    <Route path="/" component={Chrome}> 
    <IndexRoute component={Home}/> 
    <Route path="catagory" component={CategoryPage}/> 
    <Route path="*" onEnter={reloadPage}/> 
    </Route> 
); 

try { 
    ReactDOM.render((
     <Router history={browserHistory}>{routes}</Router> 
    ), 
    rootEl 
); 
} catch (err) { 
    if (err !== "Route not found") { 
    throw err; 
    } 
} 

をそれを考え出しました

関連する問題