使用BrowserRouter时获取URL中的哈希值

时间:2017-08-13 20:31:45

标签: reactjs react-router react-redux react-router-dom

正如我所理解的那样,来自react-router v4的BrowserRouter不应再在URL中使用#,但对我来说,哈希仍然是因为某些奇怪的原因而添加的......

import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom';
import {Provider} from 'react-redux';
import {createStore, applyMiddleware} from 'redux';
import app from './reducers/reducers.js';
import thunkMiddleware from 'redux-thunk';
import {polyfill} from 'es6-promise'

import App from './components/app.jsx';

let store = createStore(app, {
    setAuthenticated: false
    },
    applyMiddleware(
        thunkMiddleware
    ));

ReactDOM.render((
    <Provider store={store}>
        <BrowserRouter basename={'/'}>
            <App />
        </BrowserRouter>
    </Provider>
), document.getElementById('app'));

使用BrowserRouter时,我不应该“无哈希”吗?或者redux以某种方式影响BrowserRouter?

1 个答案:

答案 0 :(得分:0)

只是解决了同样的问题: 检查您是否正在使用可直接用于哈希的组件(例如我所处的环境中的createHashHistory) 抱歉,迟到了答案)