Navigation in a single page app with react.js

有些话、适合烂在心里 提交于 2019-12-04 12:17:26

问题


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. 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.

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.

or 2. have a general react component and define a state variable that represents which content to render.

Any help would be greatly appreciated!


回答1:


Have you heard about react router? Seems to be what you want. react router



来源:https://stackoverflow.com/questions/32030474/navigation-in-a-single-page-app-with-react-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!