How to Prevent FQDN when using React Router with hashHistory

时间:2016-04-15 15:19:12

标签: reactjs react-router

When using the hashHistory approach with react-router and clicking on a <Link to="/admin">Admin Screen</Link>, I see this in my browser's address bar: http://localhost:8080/path/to/app/#/http://localhost:8080/path/to/app/admin?_k=emdg1n

I was expecting: http://localhost:8080/path/to/app/#/admin?_k=emdg1n

Oddly, I do end up at the Admin Screen visually but also I receive this error in my console:

Warning: [react-router] Location "/http://localhost:8080/path/to/app/admin" did not match any routes

When I use the browserHistory method I do not see any problems.

I'm hoping I'm missing somethings easy -- note that my app is not at the root of the web server, so my routes are configured like this currently:

<Route path='/path/to/app/' component={App}>
    <IndexRoute component={Home}/>
    <Route path="/" component={Home}/>
    <Route path="/home" component={Home}/>
    <Route path="/about" component={About}/>
    <Route path="/admin" component={Admin}/>
</Route>

EDIT: I just can't seem to track down why the absolute/fully-qualified domain name is showing up in the route. It appears this has to do with having <base href="http://localhost:8080/path/to/app/"> in my HTML source. I think the conflict might be with the history library that is used by react-router.

<!DOCTYPE html>
<html lang="en">
    <head>
        <base href="http://localhost:8080/path/to/app/">
    </head>
    <body>
        <span id="root"></span>
        <script src="includes/scripts/index.js"></script>
    </body>
</html>

Thanks for any assistance!

0 个答案:

没有答案