Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

javascript - react-router location did not match any routes

I am stuck with react-router routing. I am getting the error:

Warning: [react-router] Location "/FluxApp/" did not match any routes

This is my app.js:

var React = require('react');
var ReactDOM = require('react-dom');
var Router = require('react-router').Router;
var Route = require('react-router').Route;
var IndexRoute = require('react-router').IndexRoute;
var browserHistory = require('react-router').browserHistory;

var App = require('./views/App');
var Home = require('./views/Home');


var Routes = (<Router history={browserHistory}>
               <Route path="/" component={App}>
                 <IndexRoute component={Home} />
               </Route>
              </Router>);

ReactDOM.render(Routes, document.getElementById('content'));

My App.js like below:

var React = require('react');
var RouteHandler = require('react-router').RouteHandler;

var App = React.createClass({
  render: function() {
     return (
        <RouteHandler />
     );
  }
});

module.exports = App;

My Home.js like below:

var React = require('react');

var Home = React.createClass({

  render: function() {
    return (
      <div>
        Home
      </div>
    );
  }

});

module.exports = Home;

Here is hieararchy of my project:

/FluxApp
   |...
   +/js
   .  |
   .  +/actions
   .  +/constants
   .  +/dispatcher
   .  +/stores
   .  +/views
   .  .     |
   .  .     App.js
   .  .     Home.js
   .  app.js
   .
   index.html

As you guess, I build app.js with browserify and create bundle.js and I am using that bundle.js in script tag in index.html

Here are versions my everything using in project.

"dependencies": {
   "classnames": "^2.2.3",
   "flux": "^2.1.1",
   "keymirror": "^0.1.1",
   "object-assign": "^1.0.0",
   "react": "^0.14.6",
   "react-dom": "^0.14.6",
   "react-router": "^2.0.0-rc5"
},
"devDependencies": {
   "browserify": "^6.2.0",
   "envify": "^3.0.0",
   "jest-cli": "^0.4.3",
   "reactify": "^0.15.2",
   "uglify-js": "~2.4.15",
   "watchify": "^2.1.1"
},

So, when I try to go to "http://localhost:8080/FluxApp/" I get always same error : "Warning: [react-router] Location "/FluxApp/" did not match any routes"

How can i solve this ? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your Routes don't actually specify a route for /FluxApp.

You'd need something like:

in app.js

var Routes = (<Router history={browserHistory}>
               <Route path="/FluxApp/" component={App}>
                <IndexRoute component={Home} />
               </Route>
              </Router>);

in App.js

var App = React.createClass({
  render: function() {
    return this.props.children;
  }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...