0

因此,正如标题所描述的那样,我正在 github 上的 denlillemand/react 上做一个可用的应用程序。它有一个快速后端,只提供一个简单的 html 模板来导入我的 bundle.js。该应用程序最初渲染得很好,但似乎没有一条路线有效。

以下是涉及的组件:

./Application.js

   import React from "react"; 
   import Marty from "marty"; 
   import actions from "./actions";
   import stores from "./stores";
   import queries from "./queries";
   import sources from "./sources";
   import Router from "./Router";
   import RealApp from "./components/App";

class Application extends Marty.Application {
  constructor(options) {
  super(options);
  this.register(actions);
  this.register(stores); 
  this.register(queries);
  this.register(sources);
  this.router = Router;
  }
}

var app = new Application();
var { ApplicationContainer }  = require('marty');

app.router.run(function(Handler,state){
      React.render((
              <ApplicationContainer app={app}>
                      <Handler{...state} />           
              </ApplicationContainer>         
      ), document.getElementById("app"));
});

./components/App.js

 import React from "react"; 
 import Router from "react-router";
 import Header from "./core/Header";
 import Footer from "./core/Footer";

 var RouteHandler = Router.RouteHandler;

 export default class App extends React.Component {
   constructor(props) {     
    super(props);          
    this.state = {         
    }
  } 
  render() {
    return (
      <div>                
       <Header />           
       <RouteHandler />
       <Footer />           
      </div>               
     );
   }
} 

./Routes.js

 import React from "react";
 import {Route} from "react-router";
 import {DefaultRoute} from "react-router";
 import App from "./components/App";
 import About from "./components/About";
 import ChapterOne from "./components/chapterone/ChapterOne";
 import ChapterTwo from "./components/chaptertwo/ChapterTwo";
 import ChapterThree from "./components/chapterthree/ChapterThree";
 import ChapterFour from "./components/chapterfour/ChapterFour";

  export default (
          <Route name="app" path="/" handler={App}>
                <Route path="/about" handler={About}/>
                <Route path="/chapters/chapterone" handler={ChapterOne} />
                 <Route path="/chapters/chaptertwo" handler={ChapterTwo} />
                 <Route path="/chapters/chapterthree" handler={ChapterThree} />
                 <Route path="/chapters/chapterfour" handler={ChapterFour} />
                 <DefaultRoute name="default" handler={About}/>
         </Route>
  );

./Router.js

  import Router from "react-router";
  import routes from "./Routes";

  let location = () => {
       if(typeof window !== undefined){
         return Router.historyLocation;
       }
   } 

    export default Router.create({
         routes:routes,
         location:location()
     }); 

默认路由似乎是唯一有效的路由,因为我点击了 About 组件。这个应用程序在不久前是 SSR 时工作,我有点想知道我是否正确设置了 react-router,但看看 DOCS 似乎我有。

4

1 回答 1

0

我想我必须回答我自己的问题,

MartyJS 的创建者最近终止了他自己的项目,如果你关注他的推特,他宣布了它.. 所以我想我会转向 redux,因为它有 3500 多个 github 启动,我想找到对出现的 redux 问题的支持会更容易.

谢谢 。

于 2015-08-02T14:59:08.980 回答