admin管理员组

文章数量:1287632

I see in the React Router docs that you pass into ponents the match prop, and you can call match.url, but you never seem to actually pass in anything to the ponent. So what exactly is match and where are you getting it from?

I see in the React Router docs that you pass into ponents the match prop, and you can call match.url, but you never seem to actually pass in anything to the ponent. So what exactly is match and where are you getting it from?

Share Improve this question asked Dec 11, 2017 at 22:28 JorahFriendzoneJorahFriendzone 4331 gold badge7 silver badges23 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Hope this helps: https://reacttraining./react-router/web/api/match

You get match in the props, usually when your ponent is called by a Route you will get it, and you can pass it down to other ponents as regular props to extract or use the information.

location is also very useful when interacting with react-router. I usually use match to do rendering and redirecting depending on the isExact flag, and location to have the actual URL that the browser has.

See match() is pure JavaScript's String property. So if match is used in JSX, then react also made it's custom property match so that it does not conflict with main match() and it is global object for React Router.

I have faced this issue and worked out knowing that don't need to worry that it should be passed in props or state. In fact it is custom property in JSX which does not conflict with actual String.prototype's property.

So without messing your head, just think it as of match() property that is from global Object specially used in React Router

本文标签: javascriptWhat exactly is matchurl in React RouterStack Overflow