Git Product home page Git Product logo

meteor-reaktor's Introduction

Reacktor

Easy to use React Frontend for FlowRouter

With Reacktor you can write routes like this:

  Reaktor.init(
    <Router>
      <Route path="/" layout={Layout} content={BlogList} />
      <Route path="/blog/:page" layout={Layout} content={BlogPost} />
      <Route path="/about" layout={About} />
        <Route path="/about/company" layout={Layout} content={Company}  />
    </Router>
  );

Behind the schenes, it uses FlowRouter and ReactLayout.

Installation

First add FlowRouter 2.0 or FlowRouter SSR into your app:

meteor add kadira:flow-router
// or
meteor add kadira:flow-router-ssr

Then add Reaktor

meteor add kadira:reaktor

Usage

Let's say we've two React components like this:

BlogList = React.createClass({
  render() {
    return (
      <div>
        This is the blog list:
        <ul>
          <li><a href="/blog/hello-post">Hello Post</a></li>
        </ul>
      </div>
    );
  }
});

BlogPost = React.createClass({
  render() {
    return (
      <div>
        <p><a href="/">Back</a></p>
        This is the blog post
      </div>
    );
  }
});

Then, here's the layout:

Layout = React.createClass({
  render() {
    return (
      <div>
        <h1>My Blog </h1>
        {this.props.content}
      </div>
    );
  }
});

Now let's create routes:

Reaktor.init(
    <Router>
        <Route path="/" layout={Layout} content={BlogList} />
        <Route path="/blog/:postId" layout={Layout} content={BlogPost} />
    </Router>
);

Accessing Route Context

Then, you can access the FlowRouter's current context inside BlogList and BlogPost component using their props. See:

BlogPost = React.createClass({
  componentWillMount() {
    var postId = this.props.params.postId;
    console.log("This the postId:", postId);
  },
  render() {
    ...
  }
});

Passing Route Options

You can also pass FlowRouter route options like name and triggersEnter like this:

  Reaktor.init(
    <Router>
      <Route 
        path="/" 
        name="homePage"
        layout={Layout} 
        content={BlogList} 
        triggersEnter={homePageLogger}/>
    </Router>
  );

  function homePageLogger(context, redirect) {
    if(context.queryParams.forwardToBlog) {
      redirect("/blog");
    }
  }

meteor-reaktor's People

Contributors

arunoda avatar maxim-filimonov avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.