Creating a Single-Page App in React using React Router

You can try adding the exact prop to your Route: <Route exact path="/about"/>

That should do it :slight_smile:

1 Like

hi i have upload this source to github

2 Likes

can you implement all the react JS component life cycle in a single page which have home about and contact tabs?

Thank you, this tutorial helped me a lot to get start with React.

1 Like

When i add the css it donā€™t load into the web, why this happened?

Do you have the import statement for the CSS file specified? :slight_smile:

yep of course, like u put it

Strange. If you add something like the following into your CSS, does everything look bigger?

* {
   font-size: 200px;
}

Sometimes the selector names are misspelled or a random . or # has been added to a HTML tag selector :slight_smile:

first & foremost, excellent series of posts - very informative and clear. Kudos to you !!

Just wondering - was there any reason you did not implement the styling in the ā€˜React wayā€™ that you advocated in ā€œStyling in Reactā€, for this tutorial?

thanks

Haha! I think you are referring to that I wrote here:

With that said, you should pick and choose the [styling] techniques that make the most sense for your situation. While I am biased towards Reactā€™s way of solving our UI development problems, Iā€™ll do my best to highlight alternate or conventional methods as well. Tying that back to what we saw here, using CSS style rules with your React content is totally OK as long as you made the decision knowing the things you gain as well as lose by doing so.

There really is no ā€œone trueā€ approach haha:

  • For web sites like what we are basically dealing with in this example, the traditional CSS file with style rules is easier to maintain.

  • When Iā€™m dealing with components used as part of a larger React app, then I lean towards the ā€œReact wayā€ of styling using an object.

  • My preferred approach is to have a CSS file per component similar to what you see in the todolist tutorial. It provides the flexibility of CSS, specificity, the cascade, and other good things. It also keeps things isolated enough to have each component be independent-ish.

Use whatever approach makes sense for you. All of these approaches have their Pros and Cons :stuck_out_tongue:

(Glad you like these articles! Thanks for the nice comments!!!)

Cheers,
Kirupa

Thanks for sharing your work. I see that youā€™re using css. I am wondering if I should use react-bootstrap?
Any advice?
Thanks again!

Thanks for the tutorial. Need more help

Thanks so much! So many of the React tutorials out there get so complex very quickly. I feel like you have a great balance of detail which is explained very clearly and in a way you donā€™t need to be an expert to implement. Exactly what I needed to carry learnings across to my own React SPA project - thanks again!!

1 Like

Glad you liked the content and the way it was presented :slight_smile:

Thanks, I just need clone the code from github, thatā€™s save my time.

Hi @kirupa ,

I really enjoy your articles on React. Theyā€™re extremely helpful and informative with learning React and gaining confidence with it.

Iā€™m running into a bit of an issue with React Router, though. Iā€™ve adapted this tutorial into a bit larger of an app to give it navigation, but it seems that if I use components with state in the routes, I run into this warning and my app stops functioning properly after navigating away from the component with state: ā€œCanā€™t call setState on an unmounted componentā€¦ā€

Iā€™m sure itā€™s something simple that Iā€™m missing, but Iā€™ve been fighting with this for a while now and my frustration is clouding my ability to spot details. Would you mind giving some advice on increasing the complexity of an app that uses React Router?

I have a project on Github that exhibits this behavior if you need to see it in action

You are running into a very common issue that everybody runs into. This blog post provides more details on what you can try: https://reactjs.org/blog/2015/12/16/ismounted-antipattern.html

Let me know if that helps :slight_smile:

Well, see hereā€™s the thing about that. Iā€™ve run into a few articles that mention this issue, and it makes sense, but I donā€™t think Iā€™m doing this exactly. Iā€™m not using isMounted at all, and Iā€™m not using Flux for this project. Iā€™m simply calling setState in a function thatā€™s called in componentDidMount and then in a handler thatā€™s passed to a lower-level component (which itself never calls setState), which looks legal to my inexperienced eyes.

Hereā€™s the project Iā€™m working on that exhibits this issue. Youā€™ll see the BrowserRouter used in src/App.js and itā€™s the handleSelect(id) function in the ADD2Characters class that raises the warning.

Could it have something to do with the onClick in ADD2CharacterTable? I just noticed that while looking it over again

I think I just managed somethingā€¦ I just made a commit to that repo that converts the ADD2CharacterTable component to a function component, and this appears to get around the issue. Would you agree with this solution, or is it just a hack made by someone who doesnā€™t know any better? :slight_smile:

1 Like

After looking through your code, I am not 100% sure why you had the original problem to begin with haha. With that said, avoiding any knowledge of state by going to a functional component is one way of avoiding this issue entirely. Since your app works fine now, I wouldnā€™t question it too much! :slight_smile: