How to use same URL for inertia and axios call?

Viewed 14

i have a link in web page which returns user component

 public function index(Request $request)
    {
        if($request->headers->has('x-inertia')){
            return Inertia::render('Users/UserList', [
                'users' => User::all()->map(function ($user) {
                    return [
                        'id' => $user->id,
                        'name' => $user->name,
                        'email' => $user->email,
                    ];
                }),
            ]);
        }

        $users= User::all();
      
        return [
            'data' => $users,
        ;

    }

I am using same Route for ajax call in my datatable on that component.The problem is when i refresh the page it return cached JSON. enter image description here

I tried adding extra parameters with the axios request

axios.interceptors.request.use(function (config) {
        
        config.url += (config.url.indexOf('?') > -1 ? '&url-ts=' : '?url-ts=')+ 
        moment().format('x');
        return config;
    },  function (error) {
          return Promise.reject(error);
    });

so the GET Url for component is : http://localhost/alias-name/users

and For Axios Call: http://localhost/alias-name/users?_=1663741798162

Still the same issue persist on refresh page. I am using laravel 9 + inertia + vue 3

0 Answers
Related