deladels's avatar

Defining routes in a react component using Inertia

<td>{event.price/100}</td>
 <td>
	<InertiaLink href={route('event.show', event.id)}>
		View
	</InertiaLink>
</td>

So form the above code, I've been trying to use the route function with inertia js which is defined in the backend but what happens is that the component isn't rendered and throws an error saying the route is not defined.

Error:

Uncaught ReferenceError: route is not defined
    at app.js:33244
    at Array.map (<anonymous>)
    at app.js:33240
    at renderWithHooks (app.js:18235)
    at mountIndeterminateComponent (app.js:21061)
    at beginWork (app.js:22299)
    at HTMLUnknownElement.callCallback (app.js:7195)
    at Object.invokeGuardedCallbackDev (app.js:7244)
    at invokeGuardedCallback (app.js:7306)
    at beginWork (app.js:27209)

Anyway to fix this?

0 likes
7 replies
LaCoder's avatar

@Sinnbeck I am getting errors that the route is not defined, even route is given in web.php -> Solved by giving name to route, but getting below error now,

router.ts:5 
        
       Uncaught Error: useHref() may be used only in the context of a <Router> component.

here is link component,

   <ListItemButton>
                <ListItemIcon>
                        <LogoutOutlined />
                    </ListItemIcon>
                   
                    <Link href={route('demo')}>
                        <ListItemText primary="Bills" />
                    </Link>
                </ListItemButton>
Sinnbeck's avatar

@LaCoder you syntax in the first post is correct. Did you remember to add the helper to your blade file?

@routes() 
Sinnbeck's avatar

@LaCoder not sure where router.ts comes from. Are you using react router or is that a inertia file?

LaCoder's avatar

@Sinnbeck I am trying to integrate a theme which has React Router and me trying to use Intertia, so it seems it is conflicting somewhere, I will try to find out where it is wrong.

Sinnbeck's avatar

@LaCoder ok. You should create a new thread as this does not sound to be related :)

1 like

Please or to participate in this conversation.