我結束了去爲是更新我的反應容器有tabindex="-1"
,並呼籲document.getElementById('content').focus()
內onUpdate
的解決方案。這對我來說就像是黑客攻擊,所以我不確定這是否是正確的解決方案。
的index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="UTF-8">
<title>Todo App</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="mobile-web-app-capable" content="yes">
</head>
<body>
<div id="content" tabindex="-1" />
<script src="index.js"></script>
</body>
</html>
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, browserHistory } from 'react-router';
import routes from './routes';
let element = document.getElementById('content');
ReactDOM.render(<Router onUpdate={() => document.getElementById('content').focus()}
history={browserHistory} routes={routes} />, element);
讓你找到如何調用JS的路由器導航? –
我做過,我一直在使用'onUpdate'做其他事情。 –