Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

When should I use the `match.path` over `match.url`?

This is in reference to React's React Router DOM library.

1 Answer

Ondrej Salamon
Ondrej Salamon
1,501 Points

I suppose it depends on an problem you're solving.

I don't know any of React stuff or course your question is related to but generally speaking, url is "complete" address, i.e. string with protocol + domain + path + parameters, anchors etc. whereas path is just a part of url after domain (and "/") and without parameters, anchors etc.

URL: "http://www.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument" PATH: just "/path/to/myfile.html" (Source: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL)

So if you want to match something inside your app or on your local server I'd say it is safer to use "path". Because you want to match your local files or paths inside root folder of your local server you don't care about domain, protocol and so.