Location did not match any routes (1.0.0-rc1)
_configuration/routes.js
import React from 'react';
import {Router, Route, IndexRoute} from 'react-router';
import App from './app';
import UserList from '../user-list/user-list';
import UserPrettyList from '../user-list-pretty/user-list-pretty';
import UserDetails from '../user-details/user-details';
import Error404 from '../errors/error-404.js';
export default function(history) {
return (
<Router history={ history }>
<Route path="/" component={ App }>
<IndexRoute component={ UserList }/>
<Route path="pretty" component={ UserPrettyList }/>
<Route path="users/:id" component={ UserDetails }/>
<Route path="*" component={ Error404 }/>
</Route>
</Router>
);
};
client.js
import React from 'react';
import Router from 'react-router';
import { createHistory, useBasename } from 'history';
import routes from './_configuration/routes';
// Add promise support for browser not supporting it
import es6Promise from 'es6-promise';
es6Promise.polyfill();
require('./_configuration/main.less');
const history = useBasename(createHistory)({basename: '/'});
React.render(routes(history), document.body);
this code not work at the client side, why? I'm try to open in browser url: http://localhost:3000/pretty Error in console: Warning: Location "pretty" did not match any routes
+1
Have you tried without calling useBasename, just createHistory?
I'm experiencing what I think is a similar problem.
client.js
import React from 'react';
import Root from './containers/Root';
import { createHistory } from 'history';
//Needed for onTouchTap
//Can go away when react 1.0 release
//Check this repo:
//https://github.com/zilverline/react-tap-event-plugin
var injectTapEventPlugin = require("react-tap-event-plugin");
injectTapEventPlugin();
React.render(
<Root history={new createHistory()} />,
document.getElementById('app-container')
);
Root.jsx
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { Router, Route, RouteHandler, Redirect, IndexRoute } from 'react-router';
import configureStore from '../store/configureStore';
import Layout from '../containers/Layout';
import Groups from '../containers/Groups';
const store = configureStore();
export default class Root extends Component {
render() {
return (
<Provider store={store}>
{() =>
<Router history={this.props.history}>
<Route path='/' component={Layout}>
<IndexRoute component={Groups} />
</Route>
</Router>
}
</Provider>
);
}
}
I first ran into it on the weekend and was experiencing the issue as infinite redirects (using hashHistory). I've since npm updated history and switched to plain createHistory and instead I get urls like http://localhost:3000/#/?_k=5ja9he when I visit / with a console warning of Warning: Location "/" did not match any routes
I hope I'm just doing something stupid, any help would be appreciated.
+1
+1
I'm not entirely sure what this issue is about?
@paveleremin and @joho seems like two different issues to me, one of you is using redux the other is not. Not sure what +1 means? Do you have the same issue as both of them?
I'm happy to help but only if I can understand what the actual issue is.
@joho please have a look here on how to use Redux with React Router.
@paveleremin I put the simple example on how to use React Router 1.0.0-rc1:
import React, { PropTypes, Component } from 'react';
import createBrowserHistory from 'history/lib/createBrowserHistory';
import { Router, Route, Link, IndexRoute } from 'react-router';
class Navigation extends Component {
render() {
return (
<div>
<ul>
<li><Link to='/'>Main</Link></li>
<li><Link to='/about'>About</Link></li>
<li><Link to='/contact'>Contact</Link></li>
</ul>
</div>
);
}
};
class Contact extends Component {
render() {
return <div>Contact</div>;
}
}
class About extends Component {
render() {
return ( <div>About</div> );
}
}
class Home extends Component {
render() {
return <div>Home</div>;
}
}
class App extends Component {
render() {
return (
<div>
<h1>App</h1>
<Navigation />
{this.props.children}
</div>
);
}
}
export default class Root extends Component {
render() {
return (
<Router history={createBrowserHistory()}>
<Route path='/' component={App}>
<IndexRoute component={Home} />
<Route path='about' component={About} />
<Route path='contact' component={Contact} />
</Route>
</Router>
);
}
}
please use it as an example, it should solve your problems
ok,I think I have solved my problem.
just use history.js , do not pay attention to 'history/lib/createBrowserHistory'.
Router.jsx
import React from 'react';
import { Router, Route, Link, IndexRoute } from 'react-router';
import { createHashHistory } from 'history';
/* Import Component */
import Home from './pages/home.jsx';
import Layout from './pages/layout.jsx';
/* create history for router */
let history = new createHashHistory();
/* Router Config */
const routes =
<Router history={history}>
<Route path="/" component={Layout}>
<IndexRoute component={Home} />
<Route path="home" component={Home} />
</Route>
</Router>
;
/* export a function for app.js to run whole the app. */
export function start(){
let rootInstance = React.render(routes , document.getElementById('app'));
if (module.hot) {
require('react-hot-loader/Injection').RootInstanceProvider.injectProvider({
getRootInstances: function () {
return [rootInstance];
}
});
}
};
home.jsx
import React from 'react';
const Home = React.createClass({
tranitionTo(){
this.props.history.pushState(null, 'the route you wanna go');
}
});
I had the same issue, I have routers set up like this:
let createBrowserHistory = require("history/lib/createBrowswerHistory"),
...;
<Router history={createBrowserHistory()}>
<Route path="/" component={App}>
<IndexRoute component={Home} />
<Route path="category/:name" component={Category} />
</Route>
</Router>
When I click a link, which navigates to the URL localhost:8000/category/action, it throws the error Location category/action did not match any routes. I can not see anything wrong with my setup.
There may be something wired in react-router or history?
+1
+1
Me as well, using hashHistory and browserHistory.
var ReactRouter = require('react-router');
var Router = ReactRouter.Router;
var IndexRoute = ReactRouter.IndexRoute;
var NotFoundRoute = ReactRouter.NotFoundRoute;
var Route = ReactRouter.Route;
var createHistory = require('history').createHistory;
var history = createHistory()
...
React.render((
<Router history={history}>
<Route path="/" component={Main}>
<IndexRoute component={Types} />
<Route path="types" component={Types} />
<Route path="collections" component={Collections} />
<Route path="*" component={NotFound} />
</Route>
</Router>
), document.body);
Actually, please check the Link component as described in https://github.com/rackt/react-router/blob/master/UPGRADE_GUIDE.md#links Use an absolute path instead of the name
Yep. That worked for me. Thanks.
Thanks @FredericHeem that did it -- Just needed to add a slash at the beginning of the route.
Thanks @FredericHeem @mcrider, absolute path did the trick!
Thanks for sorting that one out.
Had the same problem as a TS. In my case it was about old way I used for nested routes. I've used "Router" inside nested containers. Seems that in 1.0.0 versions it should be changed by this.props.children.
By the way, I think it's worth to add to docs.
probably it could help someone :) I had the same problem (and few additional) and this was what caused it:
import Link from 'react-router';
it should be, of course:
import {Link} from 'react-router';
@mayacode Thanks! Just made the same silly mistake :)
@mayacode: Thanks, you saved my day!