reactjs - How to make simple button navigation to other view? -


i trying make simple button navigation 1 view other ( i'm yet unsure called view or not ).

for example have featured.js as

var searchpage = require('./search');  class featured extends component {     showsearchpage(){         console.log('showing search page');         this.props.navigator.push({             title: "search",             component: searchpage         });     }      render() {         return (            <touchablehighlight onpress={() => this.showsearchpage()}>               <view style={styles.row}>                 <text style={styles.label}>open search page</text>               </view>             </touchablehighlight>                   );     } }  module.exports = featured; 

then have search.js class featured.js . how can create button in view on tap open search.js view.

currently getting "can not read property push of undefined". how define navigator or there other simple way navigate?

note: don't want make tabbar navigation.

so have app page render either subviews depending on user actions. first of suggest use state instead of props doing (it's dynamic not static).

var searchpage = require('./search'); var initial = require('./initial'); var anothersubview = // ...  class featured extends component {     getinitialstate: function() {         title: "initial",         component: <initial/>         return({title:title, component:component});     }     showsearchpage(){         console.log('showing search page');         this.setstate({             title: "search",             component: <searchpage/>         });     }      render() {         var title = this.state.title;         var component = this.state.component;         return (<div>            <touchablehighlight onpress={() => this.showsearchpage()}>               <view style={styles.row}>                 <text style={styles.label}>open search page</text>               </view>             </touchablehighlight>             {component}                   </div>);     } }  module.exports = featured; 

use getinitialstate load first/landing subview. change component on click.

by way props undefined because didn't define =p. , should use setprops. anyway think not right proceed know.

hope helps!


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -