Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the difference between these routes?

What is the difference between these Routes in react? Which one is correct and which one should I use?

<Routes>
          <Route exact path="/" element={<Home />} />
          <Route exact path="/about" element={<About />} />
          <Route exact path="/blog" element={<Blog />} />
</Routes>

or

<Routes>
          <Route exact path="/" component={Home} />
          <Route exact path="/about" component={About} />
          <Route exact path="/blog" component={Blog} />
</Routes>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Both of them works almost same, but the one use case I can think of, for using element rather than the component(as most people do) is that you can pass props via the element method(element={<Home your_props={"yay I can pass props!"} />}).

So to summarize, there’s no such correct or wrong way to do things in programming, it just depends upon your use case. If one was the wrong way, why would the developer keep it?

I hope I can help you decide which way to go.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading