Javascript 为什么我可以直接在address';有hashHistory但没有browserHistory的酒吧?
我现在发现React路由器,我有一个问题,为什么我可以用hashHistory直接在地址栏中输入URL,而不用browserHistory 这里是我尝试访问的url:Javascript 为什么我可以直接在address';有hashHistory但没有browserHistory的酒吧?,javascript,reactjs,react-router,Javascript,Reactjs,React Router,我现在发现React路由器,我有一个问题,为什么我可以用hashHistory直接在地址栏中输入URL,而不用browserHistory 这里是我尝试访问的url: localhost:3000/element/createform 这是我的代码: // import {...} // then the code content <ApolloProvider client={client} > <Router history={has
localhost:3000/element/createform
这是我的代码:
// import {...}
// then the code content
<ApolloProvider client={client} >
<Router history={hashHistory}>
<Route path="/" component={App}>
<IndexRoute component={ElementList}/>
<Route path="element/createform" component={CreateForm} exact/>
</Route>
</Router>
</ApolloProvider>
//导入{…}
//然后是代码内容
对于browserHistory,它返回我“无法获取路径”,但对于hashHistory,它可以工作。那么为什么呢?您需要web服务器始终返回主HTML文件 如果调用example.com/index.html/test,浏览器将请求example.com/index.html,然后让index.html处理散列(至少在这里)
如果您调用example.com/index.html/test,您的浏览器将请求另一个名为test的文件,该文件在服务器上找不到。您可以使用
browserHistory
手动更改url,但由于浏览器的性质,它将向服务器发出新的请求。你能把给你这个错误的代码包括进来吗?好的,我已经编辑了我的代码很好,这是URL。你能把代码包括在路由器
,路由
中吗?我明白了,好的,我已经编辑了我的主题