Javascript 导航栏导航
我是新的反应,我有问题的路由。我希望导航栏在某些页面上呈现,但在其他页面上不呈现。正确的方法是什么?我知道我不应该在特定的组件中渲染它 如果这是我的app.jsJavascript 导航栏导航,javascript,reactjs,react-router,Javascript,Reactjs,React Router,我是新的反应,我有问题的路由。我希望导航栏在某些页面上呈现,但在其他页面上不呈现。正确的方法是什么?我知道我不应该在特定的组件中渲染它 如果这是我的app.js var App = React.createClass ({ render (){ return ( <div> <NavbarInstance /> </div> ); } }); document.write('<div i
var App = React.createClass ({
render (){
return (
<div>
<NavbarInstance />
</div>
);
}
});
document.write('<div id="container"></div>');
ReactDom.render(
<Router history={createHistory({ queryKey: false })}
onUpdate={() => window.scrollTo(0, 0)}>
<Route path="/" component={App} />
<Route path="/login" component={LoginForm} />
<Route path="/other" component={Other} />
</Router>,
document.getElementById('container')
);
var-App=React.createClass({
渲染(){
返回(
);
}
});
文件。写(“”);
ReactDom.render(
window.scrollTo(0,0)}>
,
document.getElementById('容器')
);
这是我的登录页面(请参阅navbar实例)
从“React”导入React;
从“react bootstrap/lib/Input”导入输入;
从“./components/header.jsx”导入NavbarInstance;
const LoginForm=React.createClass({
getInitialState:函数(){
返回{
用户名:“”,
密码:“”
}
},
渲染(){
返回(
登录
)
}
})
导出默认登录表单
一个选项是在主应用程序组件的状态变量中跟踪您所处的页面。然后添加一个检查(如果页面是“索引”,则表示您不想呈现它)
return (
{ if (this.state.page !== 'index')
return <NavbarInstance />
}
)
返回(
{if(this.state.page!=='index')
返回
}
)
一个选项是在主应用程序组件的状态变量中跟踪您所处的页面。然后添加一个检查(如果页面为“索引”,则表示您不希望呈现该页面)
return (
{ if (this.state.page !== 'index')
return <NavbarInstance />
}
)
返回(
{if(this.state.page!=='index')
返回
}
)