React中Link组件路径报错:路径不可为完整URL的问题咨询
Hey there! Let's sort out that warning you're getting with React Router's <Link> component.
Why the Warning Happens
The to prop of React Router's <Link> is designed for client-side routing paths—it expects just the pathname, search params, and hash, not a full URL including the domain. When you concatenate serverConstants.DOMAIN_URL (which is a full domain) to your path, you're passing a complete URL, which triggers that warning.
Solutions Based on Your Use Case
1. If This is a Client-Side Route (Handled by Your React App)
Use a root-relative path (starting with /) instead of concatenating the domain. This ensures the path resolves from your app's root, not the current URL:
<li className="hidden-xs hvr-shutter-out-vertical"> <Link to='/category/tehran/fast_food'>فست فود</Link> </li>
This will correctly navigate to http://www.shadyab.com/category/tehran/fast_food without appending to the current URL, and the warning will disappear.
2. If This is an External Link (Non-React Route)
If this link points to a page outside your React app's routing system, don't use <Link> at all—use a native HTML <a> tag instead:
<li className="hidden-xs hvr-shutter-out-vertical"> <a href={serverConstants.DOMAIN_URL + 'category/tehran/fast_food'} target='_blank' // Optional: opens in new tab rel='noopener noreferrer' // Recommended for security with target="_blank" > فست فود </a> </li>
<Link> is meant for client-side SPA navigation; external links work better with the standard <a> tag.
内容的提问来源于stack exchange,提问作者S.M_Emamian

