Code Monkey home page Code Monkey logo

Comments (13)

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024 2

I think adding no-cache headers to the redirect fixed it.
Maybe this problem was here all along, but no one caught it yet... I don't know. :)
Give it a try in 2.6.2.

from laravel-localized-routes.

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024

Hello,

That is indeed strange!
Does the same thing happen with all routes, like "/about" redirecting to "/nl/about"?
Or is it just the home route?

from laravel-localized-routes.

oscaralexander avatar oscaralexander commented on May 29, 2024

Just tried it with an /about route as you suggested.

Route::get('about', function () {
    return view('about');
});

Redirects happen as follows, in this order:

  1. /about/en/about (desirable/expected)
  2. /nl/about/nl/about (desirable/expected; cookie/session locale now set to nl)
  3. /about/en/about (not desirable/expected)

Oddly, while /about redirects to /en/about, the homepage / keeps redirecting to /nl/. With use_localizer enabled, the locale cookie and session get set, but somehow forgotten or overridden by a default on a subsequent 'slugless' request.

from laravel-localized-routes.

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024

Did you add the middleware to the $middlewarePriority array in the Http/Kernel.php?
Perhaps the middleware now runs before the session get activated or something...

from laravel-localized-routes.

oscaralexander avatar oscaralexander commented on May 29, 2024

I was wondering about that... My Http/Kernel.php (Laravel 8.65) has no such array, only $middleware, $middlewareGroups, and $routeMiddleware, so I added it to $middlewareGroups.

from laravel-localized-routes.

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024

Ah yes.
They moved it to the parent class, but in some cases you still need it.
When you want to use route model binding you will definitely need it too.
You can just copy it over and add the middleware between the sessions and bindings middleware.

Edit:

The priority array is always needed, but then you have a choice:

  • add the middleware to the $middlewareGroups, the $middleware array to apply the middleware to the group or to all routes
  • set the config option use_locale_middleware to true to apply the middleware to routes within the Route::localized() closure
  • apply the middleware in the routes file, per route or group

You should only use one of the 3 options.

from laravel-localized-routes.

oscaralexander avatar oscaralexander commented on May 29, 2024

Done! The problem persists, unfortunately.

Mind you, this is a clean Laravel installation. Getting localized routes was literally the first thing I did, so there's no conflicting middleware or other stuff going on.

from laravel-localized-routes.

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024

Oh ok, can you put it somewhere so i can have look?

from laravel-localized-routes.

oscaralexander avatar oscaralexander commented on May 29, 2024

Sure Ivan, and thanks for your time and effort. You can find the brand new repo here :)

https://gitlab.com/ufomeldpunt/ufodb

from laravel-localized-routes.

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024

I don't know what changed, but weird things are happening.
I created a fresh app myself too.

If you go to /en or /nl the locale is stored in the session and in a cookie.

The FIRST time you trigger a redirect, it takes the correct locale from the session/cookie.
But after that, even tho the session and cookie changes, the redirect is cached or remembered somehow...
Even if I comment out the redirect code, or do a dd() it has no effect at all... It is still redirecting...

Also, each redirect is potentially cached for a different locale:

  • Go to /nl - sets nl locale
  • Go to / - redirects to /nl
  • Go to /en - sets en locale
  • Go to /about - redirects to /en/about
  • Go to / - still redirects to /nl

Is Laravel caching the redirect response?
I'll have to investigate deeper.

from laravel-localized-routes.

oscaralexander avatar oscaralexander commented on May 29, 2024

Is Laravel caching the redirect response?

Seems so! I'll keep an eye on this issue. Hope you find some time to look into it. Thanks and stay safe!

from laravel-localized-routes.

oscaralexander avatar oscaralexander commented on May 29, 2024

That solved it! I had to clear Chrome's permanent redirect cache, but once that was done everything worked as expected. Thanks so much!

from laravel-localized-routes.

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024

Great!
That was a brain breaker, yet such an easy fix :)

from laravel-localized-routes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.