I am currently in the process of developing an ecommerce platform, expecting users to utilize both our domain and their own custom domains. For example:
ourplatform.com/username
theirdomain.com
My goal is to customize the inline links based on the specific domain used to access the site. If it is our domain, the link structure should be /username/page
, whereas for their domain, it should simply be /page
.
Here is the code snippet I have created thus far, which only adds the username if the domain belongs to our platform:
import Link from 'next/link'
const customPath = ({ username }) => {
if (typeof window !== 'undefined') {
return window.location !== 'ourplatform.com'
? '/'
: `/${username}`
}
}
export default ({ username }) => {
const link = customPath({ username })
return (
<Link href={link}>
Home
</Link>
)
}
However, I am encountering the following error message:
Error: Failed prop type: The prop `href` expects a `string` or `object` in `<Link>`, but got `undefined` instead.
How can I successfully define different href
links based on the user's domain?