Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Problem with Axios and extra slash when used with Laravel

Time for me to ask some help as I simply do not understand the issue, spent a good 6 hours on this, going nowhere :-(

I have an Axios GET request which may have the last parameter empty.

axios.get(this.fetchAllUsersRoute + '/' + this.status + '/' + this.pagination + '/' + this.search);

My laravel route:

Route::get('/fetch-users/{status}/{pagination}/{search?}', 'MyController@fetchUsers')->name('fetch-users');

When the this.search is empty I am getting this:

Request URL: https://mywebsite.dev/fetch-users/0/1/
Request Method: GET
Status Code: 301 Moved Permanently (from disk cache)

It redirects to here on each request:

https://mywebsite.dev/fetch-users/0/1

The last / slash seems to be causing a redirection when this value is left empty.

As soon as I remove it, the problem stops...no redirection.

Any idea how I can make the last slash disappear if the last value is empty?

Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your request is incompatible with the route. You can try to create request link like below.

var fetchAllUsersRoute = "https://mywebsite.dev"
var status = 'status'
var pagination = 'pagination'
var search

var url = fetchAllUsersRoute + '/' + status + '/' + pagination + (search != null ? ('/' + search) : '')

console.log(url)
// "https://mywebsite.dev/status/pagination"

search = 'search'

url = fetchAllUsersRoute + '/' + status + '/' + pagination + (search != null ? ('/' + search) : '')

console.log(url)
// "https://mywebsite.dev/status/pagination/search"
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda