API routes requires a header that explicitly says the requester is accepting JSON, otherwise the API will respond with redirects and HTML pages instead of API results.
The router from Inertia does not add the correct header, so you will need to implement something like Axios (or another HTTP request library) and ensure that the Accept: application/json header is sent to your API.
If you've implemented Authentication for your API routes, you will need to somehow authenticate the requests with the chosen library (with Sanctum or something similar).
Completely replacing the Inertia router defeats the entire purpose with Inertia, and you'd be better off just replacing it with Nuxt or another preferred framework.
apibefore url. Example fromusers/toapi/users/. But you need to clarify the question by providing your current code.