Skip to content

Struggling to Re-Generate Routes with Inertia #822

@knightspore

Description

@knightspore

A very simple issue.

From our login page, we are redirected to admin.dashboard on successful login.

We have a set of route groups defined in config/ziggy.php:

return [
    'groups' => [
        'basic' => ['login', 'logout', 'password.*', 'guest.*'],
        'admin' => ['admin.*', 'profile.*'],
    ],
]

And we show these based on the auth status:

// app.blade.php

<head>
        // ...
        {{-- Routes --}}
        @if(auth()->user())
            @routes(['admin', 'basic'])
        @else
            @routes('basic')
        @endif
        // ...
</head>

The issue is - when we are first logged in, the <script /> block containing Ziggy routes is not re-generated. We get a browser error: Uncaught Error: Ziggy error: route 'admin.dashboard' is not in the route list.

At this point, if we hard refresh the <script /> block is successfully generated again and we now have access to all "auth" routes.

As far as I understand, this would be due to Inertia's internal handling of Navigation (ie. keeping the application shell in place when necessary).

So my question is, how can we force the @routes directive to. re-generate the routes block when we successfully login, as well as when we log out - since all the "auth" routes are now present in the <script/> block on the login page after we click "Log Out".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions