We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我把
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
换成
import {Router, Route, Switch } from 'react-router-dom'
即可。
猜测问题在于此history非彼history。
如果用BrowserRouter as Router,单独 createBrowserHistory 的 history只能改变url,并没有触发页面刷新。你会发现Link是有效的。因为Link 和 BrowserRouter 是同一个history。
The text was updated successfully, but these errors were encountered:
非常感谢你的解答,终于明白了问题所在,正是history不一致的原因。
刚简单看了下react-router的代码,BrowserRouter、HashRouter都是封装于react-router中的Router组件,其组件内部生成相应类型的history并传给Router,如果手动传入history,并不会起作用,且会打印警告(然而实际使用的时候并没有打印警告,看了编译后的代码却没有打印警告的这段,不知道为什么,源文件是有的)。
所以如果想使用自己的history,应该使用底层的react-router中的Router组件。至于为什么HashRouter可以使用,这个我也不是很明白。
Sorry, something went wrong.
No branches or pull requests
我把
换成
即可。
猜测问题在于此history非彼history。
如果用BrowserRouter as Router,单独 createBrowserHistory 的 history只能改变url,并没有触发页面刷新。你会发现Link是有效的。因为Link 和 BrowserRouter 是同一个history。
The text was updated successfully, but these errors were encountered: