Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Exact path in react-router
Aastha Pandey
Aastha Pandey

Posted on

     

Exact path in react-router

When I was usingreact router for the first time I usedpath instead ofexact path as props in component.

<Router><Switch><Routeexactpath="/"><Home/></Route><Routepath="/about"><About/></Route><Routepath="/dashboard"><Dashboard/></Route></Switch></div></Router>
Enter fullscreen modeExit fullscreen mode

In the above code when one replacesexact path topath it will match every path starting with '/', since the is inside the so, it will match the first path and don't check for the other matches.
The above code after removingexact from the will always show component and ignore or .

If one doesn't want to useexact path then the below code will work

<Router><Switch><Routepath="/about"><About/></Route><Routepath="/dashboard"><Dashboard/></Route><Routepath="/"><Home/></Route></Switch></div></Router>
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I write only on those topics, wherein I myself was stuck at some point in time.
  • Work
    Front end developer
  • Joined

More fromAastha Pandey

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp