1

I am trying to create a custom router component so that my tr links to another page passing through the data object for that row. When I click the link my not found page comes up, even when I use simple routes like '/'. I also had this issue with simplified versions I made for debugging. Heres my code:

import {setLinkProps} from 'hookrouter'

 const MyLinkButton = (props) => {
        console.log(props)
        return <button {...setLinkProps(props)} className="myButton">Click me now</button>
    }

<MyLinkButton href="/" datathing='lol'></MyLinkButton>

(Im sure that it's an error on my part, however I haven't been able to find any code example for custom router components using this library to compare with, and I was not able to understand the issue by wading through the source code.)

Linda Paiste
  • 38,446
  • 6
  • 64
  • 102
Quddus George
  • 962
  • 2
  • 14
  • 30

1 Answers1

0

Can you confirm if you are passing in as props? Based on the code, it looks like it is expecting and object with the href key. You can see this in the example given in the comments. They explicitly have {'href': route}. In your sample, you look like you are manually setting the href element in the button itself. Does your console return any errors when you click on the button?

The comments in the source code note that it

 * Accepts HTML `a`-tag properties, requiring `href` and optionally
 * `onClick`, which are appropriately wrapped to allow other
 * frameworks to be used for creating `hookrouter` navigatable links.
 *
 * If `onClick` is supplied, then the navigation will happen before
 * the supplied `onClick` action!
...
 * <MyFrameworkLink what="ever" {...useLink({ href: '/' })}>
 *   Link text
 * </MyFrameworkLink>
...
 * Accepts standard HTML `a`-tag properties. `href` and, optionally,
 * `onClick` are used to create links that work with `hookrouter`.
 * <A href="/" target="_blank">Home</A>

Your code looks like it is almost exactly what is being expected, so I assume that it is the props themselves without seeing the rest of the code. I would also remove the console log and return keywords.

You can find an example of the custom link component here in the documentation.

adlopez15
  • 3,449
  • 2
  • 14
  • 19