简体   繁体   English

使用react.js在单页面应用程序中导航

[英]Navigation in a single page app with react.js

I'm building a single page application with React and Backbone and am trying to figure out best practices for handling navigation between content in the app. 我正在使用React和Backbone构建单页应用程序,并且正在尝试找出处理应用程序内容之间导航的最佳实践。 My app will have a sidebar with links, for example, to "photos" and "settings". 我的应用程序将有一个带有链接的侧边栏,例如“照片”和“设置”。 The sidebar is always present, so upon clicking "settings" I want the settings component to be rendered without the entire page reloading. 侧边栏始终存在,因此在单击“设置”时,我希望在不重新加载整个页面的情况下呈现设置组件。 Slack is a great example of what I'm looking for, where clicking a different channel switches the conversation content, but does not reload the entire page. Slack是我正在寻找的一个很好的例子,点击不同的频道切换对话内容,但不重新加载整个页面。

I had a few ideas on how to implement this, but i'm not sure what's best: 我对如何实现这个有一些想法,但我不确定什么是最好的:

  1. Have a general react component (console.jsx) that accepts a urlparameter as a prop to determine which content (photos or settings) to render. 有一个通用反应组件(console.jsx)接受urlparameter作为prop来确定要呈现的内容(照片或设置)。

or 2. have a general react component and define a state variable that represents which content to render. 或2.具有一般反应组件并定义一个状态变量,表示要呈现的内容。

Any help would be greatly appreciated! 任何帮助将不胜感激!

Have you heard about react router? 你听说过路由器吗? Seems to be what you want. 似乎是你想要的。 react router 反应路由器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM