t4t5 / react-native-router

Awesome navigation for your React Native app.
MIT License
1.17k stars 155 forks source link

Defining the name of a page #51

Closed RWOverdijk closed 9 years ago

RWOverdijk commented 9 years ago

I've been playing around with this module a bit and so far it works really well. There's one thing that's bothering me though.. That's the name property. It looks like it's up to the initiator of the view to decide what the name of the view should be. For instance, on line 45 of HomePage.js in the twitter example:

{
  goToTweet: function(tweetData) {
    this.props.toRoute({
      name: "Tweet",
      component: TweetPage,
      data: tweetData
    });
  }
}

The name is being defined there. What if the app has several places that initiate this? Would I have to add this all over the place? Can it be defined from within the page view itself, too?

allenhartwig commented 9 years ago

You could accomplish this like so:

{
  goToTweet: function(tweetData) {
    var TweetPage = require('./pages/tweet')';
    this.props.toRoute({
      name: TweetPage.title,
      component: TweetPage.component,
      data: tweetData
    });
  }
}

with pages/tweet.js exporting:

module.exports = {
   title: 'Tweet',
   component: myTweetComponent
};
allenhartwig commented 9 years ago

Alternatively this works as well:

{
  goToTweet: function(tweetData) {
    var TweetPage = require('./pages/tweet')';
    this.props.toRoute({
      name: TweetPage.displayName,
      component: TweetPage,
      data: tweetData
    });
  }
}

Just ensure you have the displayName property defined to your desired title on within your React.createClass.

RWOverdijk commented 9 years ago

Satisfying enough. Thanks.