Skip to content
New issue

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

关于没法跳转bug #1

Open
liyatang opened this issue Jun 25, 2017 · 1 comment
Open

关于没法跳转bug #1

liyatang opened this issue Jun 25, 2017 · 1 comment

Comments

@liyatang
Copy link

liyatang commented Jun 25, 2017

我把

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。

@svkd9
Copy link
Owner

svkd9 commented Jun 26, 2017

非常感谢你的解答,终于明白了问题所在,正是history不一致的原因。

刚简单看了下react-router的代码,BrowserRouter、HashRouter都是封装于react-router中的Router组件,其组件内部生成相应类型的history并传给Router,如果手动传入history,并不会起作用,且会打印警告(然而实际使用的时候并没有打印警告,看了编译后的代码却没有打印警告的这段,不知道为什么,源文件是有的)。

所以如果想使用自己的history,应该使用底层的react-router中的Router组件。至于为什么HashRouter可以使用,这个我也不是很明白。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants