Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

panthro's avatar

Inertia, Infinite Scroll - API or Web Routes?

If i'm using Inertia like this:

This is a web route:

 public function index()
    {
        return Inertia::render('Posts/Index', [
            'posts' => Post::cursorPaginate(20),
        ]);
    }

But on that page have infinite scroll, should the infinite scroll script call an API route for subsequent data?

0 likes
5 replies
gych's avatar

For inifite scroll you could use an Axios request in your Vue/React template that fetches the data on the current page. Use js to detect when the user has reached the bottom of the element then make a call to the back end to fetch the data and update the current data.

panthro's avatar

@gych this is not what i'm asking.

I'm asking if the route called for the subsequent data should be an API route or not?

gych's avatar

@panthro You can use a web route for this but if you want to put the route in api routes you can also add 'web' middleware .

gych's avatar

@panthro You asked if you need to call an API route. In my previous reply I mentioned that its possible to add the route to your web routes but you can also add it in api routes. In the end its personal preference. Your font end and back end are connected with Inertia so adding it to api routes is not a must.

Please or to participate in this conversation.