question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flash message not showing when redirecting to same page?

See original GitHub issue

Versions:

  • @inertiajs/inertia version: 0.8.7
  • @inertiajs/inertia-vue version: 0.5.12

Describe the problem:

Flash messages are not being displayed when you redirect back to the same page? We have a page that contains a regular vue component. The component contains a form that performs a post submission. The receiving controller performs a redirect back to the same page. The flash message is not being displayed. When you redirect to another page, then the flash message is being displayed.

The initialPage.props.flash.message remains ‘null’.

What does catch my eye is that the xhr response does contain the flash message though…

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mathiasselleslachcommented, May 31, 2021

@seewhy17 , thanks for your feedback. You actually made me realise how to improve this. I was only looking for the flash messages in the created lifecycle callback (vue2 due to vuetify dependency). I have now made it a watcher that looks like this:

    watch: {
        '$page.props.flash.message': function (newValue) {
            messageStore.addItem({
                type: 'info',
                message: this.$page.props.flash.message,
            });
        }
    }

MessageStore is a messagebus that takes care of displaying the messages.

Works like a charm.

Can me closed afaik. ❤️

1reaction
seewhy17commented, Jun 5, 2021

@mathiasselleslach I think you could display the flash message in several ways You could get the message from any component by importing Inertia or usePage like so

import { Inertia } from '@inertiajs/inertia'
import { useForm, usePage } from '@inertiajs/inertia-vue3'

and get the message using Inertia.page.props.flash.message or usePage().props.value.flash.token

Alternatively, you can create a local prop flash on your component.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flask Flash message not showing after redirecting to the same ...
So when I try your new code and test it with an erroneous file upload, it does the same thing still - it...
Read more >
How to Flash messages in same page without redirecting?
I see this in the Store class, and I'm trying to use if but it's not working. Copy Code session()->now('success', 'The client was...
Read more >
Flash messages from Laravel not shown in Inertia after ...
It seems to work fine until I do a Redirect::route('auth.index')->with([...]) Then the success or error message won't fire at all. Works fine if ......
Read more >
Rails: on redirect to same page form submitted from, flash ...
Typically the flash is rendered in the application's layout file. This avoids the duplication of having to output <%= flash[:notice] %> in every...
Read more >
HTTP Redirects - The PHP Framework For Web Artisans
When you call the redirect helper with no parameters, an instance of ... to a new URL and flashing data to the session...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found