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.

VueJS application doesn't work after browser "Back" function.

See original GitHub issue

Hey Jeffrey! Thank you for the solution, it was a nice idea.

But something is still wrong, could you please take a look? I’m not sure that this is related to the Turbolinks or your solution, it might be a VueJS bug, but anyway 😃

I created a really simple form using rails-slim template:

.row.justify-content-center
  .col-sm-4
    h2 Create a new account
    = bootstrap_form_for @account do |f|
      = f.text_field :name, 'v-model': 'name'
      = f.primary 'Create Blog'
= javascript_pack_tag 'hello_vue'

It gives us an input field we need to use with VueJs:

<input type="text" name="account[name]" id="account_name" class="form-control">

And typical VueJs App:

import Vue from 'vue/dist/vue.esm'
import TurbolinksAdapter from 'vue-turbolinks'

document.addEventListener('turbolinks:load', () => {
  const element = document.getElementById('new_account')
  if (element != null) {
    const accountName = new Vue({
      el: element,
      data: {
        name: '362'
      },
      mixins: [TurbolinksAdapter]
    })
  }
});

And it works well when I went to the page (two way binding, and so on, I’m able to see it in console) Until I go to another page and come back twice 😃

Look: may-28-2017 19-50-14

Here you can see the initial state when the page is just opened. Then I got to another page and use browser “Back” button to return to the page with the New Account Form. When I did it the first time you still see 362 in the input field, but the VueJs App is already stopped and doesn’t work. When I returned the second time you can see that the field is empty at all 😃

What do you think about it? Did I miss something?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ZAKRUTKAcommented, Nov 19, 2020

meta name= "turbolinks-cache-control" content= "no-cache" in layout this helped me

1reaction
jeffreyguenthercommented, Jul 20, 2017

Fixed in 1.1.1. Update the package and you should be good to go.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VueJs won't reload Javascript on browser back button
For it to work again, I need to reload the page. I get the same results when using Materialize with Vue. The components...
Read more >
Problem with form when browser Back button pressed
Hello, I have a multi-page app (.Net Core) with Vue is implemented on a single page. On that Vue page I have an...
Read more >
How to deal with the back button in Vue?
I've noticed in my vue/laravel project that if I press the back button on the browser it doesn't repopulate my data. What is...
Read more >
VueJs won't reload Javascript on browser back button-Vue.js
It's hard to give 100% sure answer when there is no reproduction supplied but this is what might work: Try adding key parameter...
Read more >
Vue detect page refresh - Spendy Market
It offers support for Vue with its VueJS based starter app templates. Refresh token lifetime . You can configure Vue Router to redirect...
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