Basic fundamental about react-router with simple react-router example. In this tutorial we learn how you will create a custom URL in react application. Basically in React.js react-router is a routing library which responsible for routing react component and synchronize with location URL.

react router example
React router example

In this tutorial we will discuss how to navigate your web page via URL in react js. Also we create a navigation menu with react.js with some simple example.

Why React Router important for a web application?

In react application routing of component is very important. Because if you create multiple components in the application then it’s very difficult to navigate each component. And without routing you are not able to navigate the app component by URL. So react-router is important.

Now try to understand the react-router library with a simple react-router example. For example we will create some simple components like “Home, AboutUs, Service, and Products” and try to navigate via URL using the library.

Failed to compile
./src/App.js
Attempted import error: 'browserHistory' is not exported from 'react-router-dom'.

If you got the above error the make sure that you have install react-router v3 or higher if available. To Install react-router use the command below.

npm install react-router@3

You can also read

React Js Install

Best and Simple way to Install React

Click on above link to Install React


react component screensort

Best Example of React Component

Click to know how you will create react component.

React.js in Visual Studio Code

First of all create a directory under “src” in this example we create a “pages” directory under “src”. Then create javascript files like “Home, AboutUs, Service and Products”. Please see the sample code of the above file.

Sample code for the “App.js” file which basically contains the react-router library and sample routing code.

“App.js” file

import React from ‘react’;

import {RouterRoutebrowserHistoryfrom ‘react-router’;

import Home from ‘./pages/Home’;

import AboutUs from ‘./pages/AboutUs’;

import Services from ‘./pages/Services’;

import Products from ‘./pages/Products’;

function App () {
  return (
    <div>

      <Router history={browserHistory}>

        {/* for home component */}

        <Route exact path=“/” component={Home} />

        {/* for aboutUs component */}

        <Route path=“/about-us” component={AboutUs} />

        {/* as wel as services and products */}

        <Route path=“/services” component={Services} />

        <Route path=“/products” component={Products} />

      </Router>

    </div>
  );
}

export default App;

“Home.js” file

import React, {Componentfrom ‘react’;

export default class Home extends Component {
  render () {
    return (
      <div>

        <ul>

          <li><a href=“/”>Home</a></li>

          <li><a href=“/about-us”>About Us</a></li>

          {/* for url navigation we are using <a> tag you can also use Link  */}

          <li><a href=“/services”>Services</a></li>

          <li><a href=“/products”>Products</a></li>

        </ul>

      </div>
    );
  }
}

“Services.js” file

import React, {Componentfrom ‘react’;

export default class Services extends Component {
  render () {
    return (
      <div>

        <a href=“/”>Back to Home</a><br />

        Services

      </div>
    );
  }
}

“Products.js” file

import React, {Componentfrom ‘react’;

export default class Products extends Component {
  render () {
    return (
      <div>

        <a href=“/”>Back to Home</a><br />

        Products

      </div>
    );
  }
}

Output of above react router example

  • Home
  • About Us
  • Services
  • Products

You can navigate by clicking on the link .

This Post Has 108 Comments

  1. how to become a credit card processing agent

    There are actually quite a lot of particulars like that to take into consideration. That could be a nice level to deliver up. I offer the ideas above as normal inspiration but clearly there are questions like the one you bring up where crucial factor can be working in sincere good faith. I don?t know if finest practices have emerged round issues like that, however I’m positive that your job is clearly recognized as a good game. Both girls and boys really feel the affect of only a second?s pleasure, for the remainder of their lives.

  2. gem disco casino

    Hi there, just became aware of your blog through Google, and found that it is really informative. I am going to watch out for brussels. I will appreciate if you continue this in future. A lot of people will be benefited from your writing. Cheers!

  3. situs bokep

    Thanks for the tips you are sharing on this blog site. Another thing I want to say is getting hold of some copies of your credit history in order to scrutinize accuracy of any detail is the first measures you have to conduct in fixing credit. You are looking to cleanse your credit report from damaging details faults that mess up your credit score.

  4. berita bola

    Thanks , I’ve just been looking for info about this subject for ages and yours is the greatest I’ve discovered so far. But, what about the conclusion? Are you sure about the source?

  5. udinslot

    Youre so cool! I dont suppose Ive read anything like this before. So good to find any person with some original ideas on this subject. realy thank you for starting this up. this web site is one thing that is needed on the net, somebody with just a little originality. helpful job for bringing one thing new to the web!

  6. udinslot

    I loved as much as you will receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get bought an nervousness over that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly a lot often inside case you shield this increase.

  7. nevada online casino

    I like the helpful information you supply on your articles. I will bookmark your blog and check again here frequently. I am fairly sure I will be informed many new stuff right here! Good luck for the following!

  8. How to start a credit card processing company

    Thanks for the good writeup. It in truth used to be a entertainment account it. Glance complex to more brought agreeable from you! However, how could we communicate?

  9. shiohk

    Can I simply say what a reduction to search out somebody who truly knows what theyre speaking about on the internet. You undoubtedly know the way to convey an issue to light and make it important. Extra people have to read this and understand this facet of the story. I cant consider youre not more common since you positively have the gift.

  10. shiohk slot

    It is the best time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I want to suggest you some interesting things or advice. Perhaps you could write next articles referring to this article. I desire to read more things about it!

  11. 유로247

    Hi my friend! I wish to say that this article is awesome, nice written and include approximately all important infos. I would like to see more posts like this.

  12. Rateio Do Concuseiro

    you’re actually a excellent webmaster. The website loading pace is amazing. It seems that you’re doing any distinctive trick. In addition, The contents are masterwork. you have performed a wonderful job on this topic!

  13. bokep jepang

    Whoa! This blog looks just like my old one! It’s on a entirely different topic but it has pretty much the same page layout and design. Superb choice of colors!

  14. Curso Poker de Alto Nível Homem Superior

    I?m impressed, I have to say. Actually hardly ever do I encounter a blog that?s each educative and entertaining, and let me let you know, you’ve hit the nail on the head. Your thought is excellent; the difficulty is one thing that not sufficient persons are talking intelligently about. I am very pleased that I stumbled across this in my seek for one thing referring to this.

  15. download cursos telegram

    I appreciate, cause I found just what I was looking for. You have ended my 4 day long hunt! God Bless you man. Have a great day. Bye

  16. Rateio Drive

    I have been surfing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my opinion, if all site owners and bloggers made good content as you did, the web will be much more useful than ever before.

  17. curso de moda para iniciantes

    you’re really a good webmaster. The web site loading speed is incredible. It seems that you are doing any unique trick. Furthermore, The contents are masterwork. you have done a great job on this topic!

  18. automobilismo virtual bet365

    Thanks for your post right here. One thing I would really like to say is the fact that most professional areas consider the Bachelor’s Degree as the entry level standard for an online college diploma. While Associate Certifications are a great way to begin, completing a person’s Bachelors uncovers many opportunities to various professions, there are numerous on-line Bachelor Diploma Programs available through institutions like The University of Phoenix, Intercontinental University Online and Kaplan. Another concern is that many brick and mortar institutions provide Online editions of their qualifications but commonly for a significantly higher amount of money than the organizations that specialize in online college degree programs.

  19. white label payment gateway

    I believe that avoiding refined foods may be the first step to be able to lose weight. They can taste fine, but highly processed foods currently have very little nutritional value, making you consume more in order to have enough vitality to get through the day. In case you are constantly consuming these foods, moving over to grain and other complex carbohydrates will help you have more strength while taking in less. Great blog post.

  20. how to be a payment processor

    I have recently started a site, the information you offer on this web site has helped me greatly. Thanks for all of your time & work.

  21. curso de cftv online

    Definitely believe that which you stated. Your favorite justification seemed to be on the web the simplest thing to be aware of. I say to you, I definitely get irked while people consider worries that they just don’t know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people can take a signal. Will probably be back to get more. Thanks

  22. curso de sublimação senai

    One thing I want to say is that car insurance canceling is a dreadful experience and if you are doing the right things being a driver you simply won’t get one. Some individuals do receive the notice that they are officially dumped by their insurance company and many have to struggle to get further insurance following a cancellation. Low cost auto insurance rates are usually hard to get from cancellation. Having the main reasons pertaining to auto insurance termination can help people prevent completely losing in one of the most critical privileges out there. Thanks for the suggestions shared via your blog.

  23. ana otani

    Thanks for helping me to acquire new concepts about pc’s. I also contain the belief that one of the best ways to maintain your mobile computer in excellent condition is with a hard plastic case, and also shell, that matches over the top of the computer. These kinds of protective gear tend to be model targeted since they are manufactured to fit perfectly over the natural casing. You can buy these directly from the owner, or via third party places if they are for your notebook, however not every laptop could have a covering on the market. All over again, thanks for your suggestions.

  24. become an iso merchant services

    Amazing blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple tweeks would really make my blog jump out. Please let me know where you got your design. Kudos

  25. slot online

    My brother suggested I might like this web site. He was entirely right. This post truly made my day. You can not imagine just how much time I had spent for this info! Thanks!

  26. start a credit card processing company

    I do enjoy the manner in which you have presented this specific concern plus it really does present me some fodder for consideration. On the other hand, from just what I have personally seen, I simply just trust as the actual reviews stack on that people remain on point and in no way embark upon a soap box regarding the news du jour. All the same, thank you for this outstanding piece and even though I can not concur with this in totality, I value your perspective.

  27. login acekslot

    After research a number of of the weblog posts on your web site now, and I truly like your method of blogging. I bookmarked it to my bookmark web site record and might be checking again soon. Pls take a look at my web page as well and let me know what you think.

  28. kasih4d server gacor

    WONDERFUL Post.thanks for share..more wait .. …

  29. 作业代写靠谱吗

    This design is steller! You definitely know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Wonderful job. I really enjoyed what you had to say, and more than that, how you presented it. Too cool!

  30. Cookies Faça e Venda Juliana Abbud Eduk

    You made some decent points there. I regarded on the internet for the difficulty and located most people will associate with along with your website.

  31. cursos de culinária gratuito

    I have read several good stuff here. Definitely worth bookmarking for revisiting. I wonder how much effort you put to make such a magnificent informative web site.

  32. curso de consultoria de moda

    There’s noticeably a bundle to know about this. I assume you made certain good factors in options also.

  33. pro dentim

    Thanks for your write-up. Another element is that just being a photographer entails not only trouble in recording award-winning photographs but hardships in establishing the best video camera suited to your requirements and most especially situations in maintaining the quality of your camera. This really is very true and visible for those photography enthusiasts that are straight into capturing the actual nature’s exciting scenes — the mountains, the actual forests, the actual wild or the seas. Visiting these daring places definitely requires a photographic camera that can surpass the wild’s tough setting.

  34. cryptosoft judi slot

    Your place is valueble for me. Thanks!?

  35. ikariajuice

    Thanks for giving your ideas. Something is that students have an alternative between government student loan and also a private student loan where its easier to choose student loan online debt consolidation than with the federal student loan.

  36. curso de mecânica valor

    very good publish, i actually love this website, keep on it

  37. Eldridge Stohler

    Thanks for your help and for writing this post. It’s been great.

  38. Rayna Breech

    Thanks for posting. I really enjoyed reading it, especially because it addressed my problem. It helped me a lot and I hope it will help others too.

  39. Curso Magic Pyong Lee

    Another thing I’ve noticed is the fact that for many people, a bad credit score is the consequence of circumstances outside of their control. As an example they may be really saddled having an illness so they really have high bills going to collections. It would be due to a occupation loss or maybe the inability to do the job. Sometimes divorce process can really send the financial circumstances in a downward direction. Many thanks sharing your ideas on this web site.

  40. Letty Lob

    Thanks for your help and for posting this article. It’s been great.

  41. Annita Virga

    Thank you for posting such a wonderful article. It really helped me and I love the topic.

  42. graliontorile

    You could definitely see your skills within the paintings you write. The arena hopes for more passionate writers like you who aren’t afraid to say how they believe. Always go after your heart.

  43. Gbo4D

    Really when someone doesn’t be aԝare of after that its up to othedr ᥙsers that they will helρ, so
    here it takes place.

  44. zoritoler imol

    I happen to be writing to let you understand of the extraordinary encounter my cousin’s princess had visiting your site. She noticed many issues, not to mention how it is like to possess a great coaching spirit to make certain people smoothly thoroughly grasp certain hard to do issues. You undoubtedly surpassed my expected results. Thank you for producing such helpful, trustworthy, explanatory not to mention cool thoughts on your topic to Emily.

  45. zoritoler imol

    Hi my friend! I wish to say that this post is amazing, great written and come with approximately all vital infos. I’d like to peer extra posts like this.

  46. zoritoler imol

    Hello there! This is kind of off topic but I need some advice from an established blog. Is it very difficult to set up your own blog? I’m not very techincal but I can figure things out pretty fast. I’m thinking about creating my own but I’m not sure where to begin. Do you have any ideas or suggestions? With thanks

  47. zortilonrel

    I love it when people come together and share opinions, great blog, keep it up.

  48. zortilonrel

    Greetings from Colorado! I’m bored to death at work so I decided to check out your site on my iphone during lunch break. I love the knowledge you provide here and can’t wait to take a look when I get home. I’m shocked at how fast your blog loaded on my phone .. I’m not even using WIFI, just 3G .. Anyhow, good blog!

    1. Dipankar

      Thanks

  49. 출장마사지

    This is very interesting, You’re a very skilled
    blogger. I have joined your rss feed and look forward to
    seeking more of your magnificent post. Also, I’ve shared your website in my social
    networks!

  50. love someone

    Hello.This article was extremely motivating, particularly
    because I was browsing for thoughts on this subject last couple of days.

  51. bobs discount furniture

    I quite like looking through a post that will make people think.

    Also, many thanks for allowing me to comment!

  52. Ava

    Hi, i think that i saw you visited my site thus i got
    here to go back the choose?.I am trying to find issues to improve my web site!I guess
    its ok to use a few of your ideas!!

  53. slot online

    Say, you got a nice blog article.Much thanks again. Really Great.

  54. john weak

    It’s an awesome article designed for all the internet people; they will get benefit from it I am sure.

  55. there are only 10 types binary options

    Touche. Solid arguments. Keep up the good effort.

  56. Gilberto

    Fantastic site. Plenty of helpful info here.
    I’m sending it to several friends ans also sharing in delicious.
    And of course, thank you to your effort!

  57. tipsforperfectinterview.com

    Hello there, just became aware of your blog through Google, and
    found that it is really informative. I am gonna watch out for brussels.
    I’ll be grateful if you continue this in future. Numerous people
    will be benefited from your writing. Cheers!

  58. binance tesla stock

    Thanks for sharing your tһoughts ɑbout binance poloniex. Regards

  59. bandar togel

    I really like your blog.. very nice colors & theme. Did you make
    this website yourself or did you hire someone to do it for you?
    Plz reply as I’m looking to construct my own blog and would like
    to find out where u got this from. thank you

  60. Finn

    Wow that was odd. I just wrote an extremely long comment but after
    I clicked submit my comment didn’t appear. Grrrr…
    well I’m not writing all that over again. Anyway,
    just wanted to say wonderful blog!

  61. Horacio

    You’re so awesome! I do not think I’ve truly read through something like this before.
    So wonderful to find someone with some genuine thoughts on this subject matter.
    Seriously.. thanks for starting this up.
    This website is one thing that is required on the web, someone with a little originality!

  62. Gale

    WOW just what I was looking for. Came here by searching for website

  63. binary options demo contests

    If you are going for finest contents like I do, only visit this web page daily
    for the reason that it provides feature contents, thanks

  64. parents

    Іt’s amazing for me to hɑve ɑ web pagе, which is goߋd designed fօr mү experience.
    tһanks admin

  65. Url Roku Com Link

    Hey there would you mind sharing which blog platform you’re
    working with? I’m planning to start my own blog soon but I’m
    having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m looking for something
    completely unique. P.S Apologies for getting off-topic but I
    had to ask!

  66. Windows In Clarksville

    Oh my goodness! Amazing article dude! Thank you so much, However I am encountering issues with your RSS.
    I don’t understand the reason why I can’t subscribe
    to it. Is there anybody else getting the same RSS issues?
    Anybody who knows the solution can you kindly respond? Thanks!!

  67. Kristin

    We absolutely love your blog and find most of your post’s
    to be exactly I’m looking for. Does one offer guest writers to
    write content for you? I wouldn’t mind producing a post or
    elaborating on most of the subjects you write regarding here.
    Again, awesome web site!

  68. Takbehandling

    Thanks for every other magnificent post. Where else may anyone get
    that type of information in such an ideal approach of writing?
    I’ve a presentation subsequent week, and I
    am at the look for such information.

  69. Azucena

    Peculiar article, totally what I wanted to find.

  70. Alysa

    I’m no longer certain the place you are getting your info, but good topic.

    I needs to spend a while finding out much more or working out more.
    Thank you for magnificent information I was searching for this info for my mission.

  71. manhwaland

    I really like and appreciate your article post. Much obliged.

  72. 화명동출장안마

    This is the perfect web site for anybody who wishes
    to understand this topic. You know a whole lot its almost hard to
    argue with you (not that I actually will need to…HaHa).

    You definitely put a fresh spin on a topic which has been written about for years.
    Excellent stuff, just great!

  73. good massage

    Hi Dear, are you actually visiting this web site daily,
    if so after that you will definitely obtain good
    experience.

  74. 안전한출장

    I know this website provides quality depending posts and other data, is there any other website which gives these kinds of things in quality?

  75. 일산 출장 안마

    I’m not that much of a internet reader to be honest
    but your blogs really nice, keep it up! I’ll go ahead
    and bookmark your site to come back down the road.
    All the best

  76. 안전출장안마

    Wonderful article! We will be linking to this great post on our site.

    Keep up the great writing.

  77. 홈마사지

    I have been surfing online more than 3 hours today,
    yet I never found any interesting article like yours. It is pretty worth enough
    for me. Personally, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before.

  78. 출장마사지

    Wow, incredible blog format! How lengthy have you been running a
    blog for? you make blogging glance easy.
    The full look of your site is wonderful, as smartly as the
    content material!

  79. installing turf on dirt visit our website

    This is my first time go to see at here and i am actually happy to
    read everthing at alone place.

  80. Laptops

    My brother recommended I might like this blog. He used to be totally right.
    This put up truly made my day. You cann’t believe simply how so much time I had spent
    for this info! Thanks!

  81. Slot Games

    Today, I went to the beach with my kids. I found a sea shell and gave
    it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put
    the shell to her ear and screamed. There was
    a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is totally off topic but I had to tell someone!

  82. Peninsula Daily News

    Im thankful for the blog post.Really thank you! Want more.

  83. Monte

    Excellent pieces. Keep writing such kind of info on your blog.
    Im really impressed by it.
    Hi there, You have performed an excellent job. I will definitely digg it
    and for my part suggest to my friends. I’m sure they’ll be benefited from this web site.

  84. 홈 출장마사지

    I used to be suggested this blog by my cousin. I am now
    not sure whether or not this submit is written through him as nobody else know such certain approximately
    my trouble. You are incredible! Thank you!

  85. 광안리출장안마

    Pretty! This has been a really wonderful post. Many thanks
    for supplying these details.

  86. 광안리 출장안마

    Excellent weblog here! Additionally your web site loads up fast!
    What web host are you using? Can I am getting your
    affiliate link to your host? I want my web site loaded up as fast as yours lol

  87. 출장

    Good day! This is kind of off topic but I need some guidance from an established blog.

    Is it difficult to set up your own blog? I’m not very techincal but I can figure
    things out pretty quick. I’m thinking about setting up
    my own but I’m not sure where to start. Do you have any points or suggestions?
    Appreciate it

  88. Nikole

    Hey there are using WordPress for your blog platform?
    I’m new to the blog world but I’m trying to get started and create my own. Do you need any coding expertise to make your own blog?

    Any help would be greatly appreciated!

  89. 0mniartist

    I’ve been surfing online greater than 3 hours these
    days, but I never found any fascinating article like yours.
    It’s beautiful value enough for me. In my view, if all
    web owners and bloggers made just right content as you did, the internet will be much more useful than ever
    before. 0mniartist asmr

  90. Tomoko

    Hi there it’s me, I am also visiting this web site on a regular basis,
    this web site is in fact good and the viewers are in fact sharing fastidious thoughts.

  91. Dr. Instagram

    It’s very trouble-free to find out any matter on net as compared to textbooks, as I found this piece of writing at
    this website.

  92. 콜미출장마사지

    I seriously love your blog.. Excellent colors & theme.
    Did you develop this website yourself? Please reply back
    as I’m trying to create my very own website and want to
    learn where you got this from or what the theme is called.
    Thank you!

  93. anime

    Somebody essentially help to make severely posts I might state. Rafaelita Ettore Ailsa

  94. Tami

    Wow, that’s what I was searching for, what a stuff!
    present here at this web site, thanks admin of this web site.

  95. Ethan

    Valuable info. Fortunate me I found your site accidentally, and I’m surprised why
    this accident did not happened in advance!
    I bookmarked it.

  96. situs judi togel online Indonesia

    I pay a quick visit day-to-day a few web pages and sites
    to read articles, except this webpage offers quality based content.

  97. composition book primary journal

    I much like the helpful information you provide for your personal articles.
    I’ll bookmark your blog and have a look at again here frequently.
    I’m rather certain I am going to learn lots of new stuff proper
    here! Have a great time for these!

  98. zipper wallet insert for chic sparrow waypoint

    It’s an remarkable paragraph intended for each of
    the web users; they will likely take benefit as a result I am certain.

    Review my blog – zipper wallet insert for chic sparrow waypoint

  99. TishOPastick

    Really good article! We are linking to this particular great post on our
    site. Continue the excellent writing.

    Feel free to surf to my site: TishOPastick

  100. GinaVTitcomb

    Hi there, just wanted to tell you, I enjoyed this article.
    It absolutely was inspiring. Carry on posting!

    Also visit my website: GinaVTitcomb

  101. Lula

    Hello I am so thrilled I found your web site, I really found you
    by error, while I was researching on Digg
    for something else, Regardless I am here now and would just like
    to say cheers for a fantastic post and a all round interesting blog
    (I also love the theme/design), I don’t have time to look over it all at the minute but I have book-marked it and
    also added your RSS feeds, so when I have time I will be back to read
    a lot more, Please do keep up the superb work.

  102. click here

    Hi, аfter reading this awesome article і am toο cheerful to share my know-how herre woth mates.

  103. tharik

    Such an amazing blog with new updates. I love to learn more about this topic. Waiting for more like this.

    1. Dipankar

      Thanks

Leave a Reply