How to detect the user comes back to a page rather than starts browsing it?Passing data to components in vue.jsPrecedence in lifecycle hooks with Vue.js and Vue-routerVue.js 2.0 transition on dynamic route not firingVue.js router-view mounted callbackVue.js routing and JQuery - coming back from a routeVue component mounts multiple times (sometimes as many as 6 times)Vue-Router, router.onReady()Vuejs Router, conditional loading of JavaScript CodeVue computed and methods have different behavior when calledVue instance status and route redirect

Doubt on pronunciation of verbs (stressing)

Where is a warlock's soul?

delete specific character "[" from a file

How do I get a planar traveling party to use survival/spell slots for food/drink instead of an artificer's Replicate Magic Item infusion?

What is a dropfile?

Can a professor do an internship?

Is policy routing bad?

How can kinetic energy increase during a collision?

Identify the Eeveelutions

Idomatic expression for “less and less”

Bo Derek in texbook.tex?

What is my volume?

Download, upload, downstream, upstream

Invalid time zone 'UTC'

Should I report a security vulnerability?

Is there any point in adding more than 6 months' runway in savings instead of investing everything after that?

Does anyone know a basepoint-free construction of universal covers?

Why is this logic incorrect?

What is the exact definition of an Adaptation under Creative Commons?

How to communicate faster than the system clock

Pattern Matching, FullForm and DisplayForm

Can arbitrary matrices be decomposed using the Pauli basis?

What is the lowest level at which a human can beat the 100m world record (or: the presumed human limit) without using magic?

Average Two Letters



How to detect the user comes back to a page rather than starts browsing it?


Passing data to components in vue.jsPrecedence in lifecycle hooks with Vue.js and Vue-routerVue.js 2.0 transition on dynamic route not firingVue.js router-view mounted callbackVue.js routing and JQuery - coming back from a routeVue component mounts multiple times (sometimes as many as 6 times)Vue-Router, router.onReady()Vuejs Router, conditional loading of JavaScript CodeVue computed and methods have different behavior when calledVue instance status and route redirect






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0

















I've got a grid component that I use in many routes in my app. I'd like to persist its state (ie. paging, search param) and restore it when the user comes back to the grid (ie. from editing a row). On the other hand, when the user starts a new flow (ie. by clicking a link) then the page is set to zero and web service is called with the default param.



How can I recognise the user does come back rather then starts a new flow?



When I was researching the problem I've come across the following solutions.
Unfortunatelly they didn't serve me



1/ using router scroll behaviour



scrollBehavior(to, from, savedPosition) 
to.meta.comeBack = savedPosition !== null;



It does tell me if the user comes back. Unfortunately the scroll behaviour runs after grid's created and mounted hooks are called. This way I have no place to put my code to restore the state.



2/ using url param



The grid's route would have an optional param. When the param is null then the code would know it's a new flow and set a new one using $router.replace routine. Then the user would go to editing, come back and the code would know they come back because the route param != null. The problem is that calling $router.replace re-creates the component (ie. calling hooks etc.). Additionally the optional param mixes up and confuses vue-router with other optional params in the route.










share|improve this question


































    0

















    I've got a grid component that I use in many routes in my app. I'd like to persist its state (ie. paging, search param) and restore it when the user comes back to the grid (ie. from editing a row). On the other hand, when the user starts a new flow (ie. by clicking a link) then the page is set to zero and web service is called with the default param.



    How can I recognise the user does come back rather then starts a new flow?



    When I was researching the problem I've come across the following solutions.
    Unfortunatelly they didn't serve me



    1/ using router scroll behaviour



    scrollBehavior(to, from, savedPosition) 
    to.meta.comeBack = savedPosition !== null;



    It does tell me if the user comes back. Unfortunately the scroll behaviour runs after grid's created and mounted hooks are called. This way I have no place to put my code to restore the state.



    2/ using url param



    The grid's route would have an optional param. When the param is null then the code would know it's a new flow and set a new one using $router.replace routine. Then the user would go to editing, come back and the code would know they come back because the route param != null. The problem is that calling $router.replace re-creates the component (ie. calling hooks etc.). Additionally the optional param mixes up and confuses vue-router with other optional params in the route.










    share|improve this question






























      0












      0








      0








      I've got a grid component that I use in many routes in my app. I'd like to persist its state (ie. paging, search param) and restore it when the user comes back to the grid (ie. from editing a row). On the other hand, when the user starts a new flow (ie. by clicking a link) then the page is set to zero and web service is called with the default param.



      How can I recognise the user does come back rather then starts a new flow?



      When I was researching the problem I've come across the following solutions.
      Unfortunatelly they didn't serve me



      1/ using router scroll behaviour



      scrollBehavior(to, from, savedPosition) 
      to.meta.comeBack = savedPosition !== null;



      It does tell me if the user comes back. Unfortunately the scroll behaviour runs after grid's created and mounted hooks are called. This way I have no place to put my code to restore the state.



      2/ using url param



      The grid's route would have an optional param. When the param is null then the code would know it's a new flow and set a new one using $router.replace routine. Then the user would go to editing, come back and the code would know they come back because the route param != null. The problem is that calling $router.replace re-creates the component (ie. calling hooks etc.). Additionally the optional param mixes up and confuses vue-router with other optional params in the route.










      share|improve this question

















      I've got a grid component that I use in many routes in my app. I'd like to persist its state (ie. paging, search param) and restore it when the user comes back to the grid (ie. from editing a row). On the other hand, when the user starts a new flow (ie. by clicking a link) then the page is set to zero and web service is called with the default param.



      How can I recognise the user does come back rather then starts a new flow?



      When I was researching the problem I've come across the following solutions.
      Unfortunatelly they didn't serve me



      1/ using router scroll behaviour



      scrollBehavior(to, from, savedPosition) 
      to.meta.comeBack = savedPosition !== null;



      It does tell me if the user comes back. Unfortunately the scroll behaviour runs after grid's created and mounted hooks are called. This way I have no place to put my code to restore the state.



      2/ using url param



      The grid's route would have an optional param. When the param is null then the code would know it's a new flow and set a new one using $router.replace routine. Then the user would go to editing, come back and the code would know they come back because the route param != null. The problem is that calling $router.replace re-creates the component (ie. calling hooks etc.). Additionally the optional param mixes up and confuses vue-router with other optional params in the route.







      vue.js






      share|improve this question
















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 29 at 10:05







      Pawel

















      asked Mar 28 at 21:57









      PawelPawel

      11 bronze badge




      11 bronze badge

























          1 Answer
          1






          active

          oldest

          votes


















          0


















          HISTORY COMPONENT



          // component ...
          // can error and only serves the purpose of an idea
          data()
          return
          history: []

          ,
          watch:
          fullRoute: function()
          this.history.push(this.fullRoute);
          this.$emit('visited', this.visited);

          ,
          computed:
          fullRoute: function()
          return this.$route.fullPath
          ,
          visited: function()
          return this.history.slice(-1).includes(this.fullRoute)




          the data way



          save the information in the browser



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function()
          return JSON.parse(local.storage.gridData)
          ,
          set: function(dataObj)
          local.storage.gridData = JSON.stringify(dataObj)



          //...


          use statemanagement



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function() ,
          set: function(dataObj)
          this.$store.dispatch("saveGrid", gridData)



          //...


          use globals



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function()
          ,
          set: function(dataObj)
          window.gridData = dataObj








          share|improve this answer




























          • My question is about detecting whether the user comes to the page or rather comes back to the page. Let's say we have a few pages: P1, P2, P3, P4. When user navigates from P1 to P2 then P2 starts a new flow. When they go on to P3 and then back to P2 then I'd like to be notified they came back.

            – Pawel
            Mar 29 at 10:43











          • Oh ok - is this more what you are looking for: vuejs.org/v2/api/#keep-alive ?

            – Estradiaz
            Mar 29 at 10:57











          • Keep alive doesn't store the page state when you change the component. That's what happens when I navigate to another page. Anyway it's not what I'm after. I just want to be notified when the user moves back to a page in the browsing history.

            – Pawel
            Mar 29 at 11:53












          • I added some sketch of a history component, that will trigger a @visited event

            – Estradiaz
            Mar 29 at 12:15












          • Thanks for your effort. Let's say we've got Link, Page1 (it's got your code), Page2. By clicking Link the user navigates to Page1 then navigates to Page2 and then comes back to Page1. That's fine, your code works. However it fails when the user follows Link, Page1, Page2, Link, Page1 because it says the user has come back to P1 which is not true.

            – Pawel
            Mar 29 at 13:36












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407463%2fhow-to-detect-the-user-comes-back-to-a-page-rather-than-starts-browsing-it%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown


























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0


















          HISTORY COMPONENT



          // component ...
          // can error and only serves the purpose of an idea
          data()
          return
          history: []

          ,
          watch:
          fullRoute: function()
          this.history.push(this.fullRoute);
          this.$emit('visited', this.visited);

          ,
          computed:
          fullRoute: function()
          return this.$route.fullPath
          ,
          visited: function()
          return this.history.slice(-1).includes(this.fullRoute)




          the data way



          save the information in the browser



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function()
          return JSON.parse(local.storage.gridData)
          ,
          set: function(dataObj)
          local.storage.gridData = JSON.stringify(dataObj)



          //...


          use statemanagement



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function() ,
          set: function(dataObj)
          this.$store.dispatch("saveGrid", gridData)



          //...


          use globals



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function()
          ,
          set: function(dataObj)
          window.gridData = dataObj








          share|improve this answer




























          • My question is about detecting whether the user comes to the page or rather comes back to the page. Let's say we have a few pages: P1, P2, P3, P4. When user navigates from P1 to P2 then P2 starts a new flow. When they go on to P3 and then back to P2 then I'd like to be notified they came back.

            – Pawel
            Mar 29 at 10:43











          • Oh ok - is this more what you are looking for: vuejs.org/v2/api/#keep-alive ?

            – Estradiaz
            Mar 29 at 10:57











          • Keep alive doesn't store the page state when you change the component. That's what happens when I navigate to another page. Anyway it's not what I'm after. I just want to be notified when the user moves back to a page in the browsing history.

            – Pawel
            Mar 29 at 11:53












          • I added some sketch of a history component, that will trigger a @visited event

            – Estradiaz
            Mar 29 at 12:15












          • Thanks for your effort. Let's say we've got Link, Page1 (it's got your code), Page2. By clicking Link the user navigates to Page1 then navigates to Page2 and then comes back to Page1. That's fine, your code works. However it fails when the user follows Link, Page1, Page2, Link, Page1 because it says the user has come back to P1 which is not true.

            – Pawel
            Mar 29 at 13:36















          0


















          HISTORY COMPONENT



          // component ...
          // can error and only serves the purpose of an idea
          data()
          return
          history: []

          ,
          watch:
          fullRoute: function()
          this.history.push(this.fullRoute);
          this.$emit('visited', this.visited);

          ,
          computed:
          fullRoute: function()
          return this.$route.fullPath
          ,
          visited: function()
          return this.history.slice(-1).includes(this.fullRoute)




          the data way



          save the information in the browser



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function()
          return JSON.parse(local.storage.gridData)
          ,
          set: function(dataObj)
          local.storage.gridData = JSON.stringify(dataObj)



          //...


          use statemanagement



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function() ,
          set: function(dataObj)
          this.$store.dispatch("saveGrid", gridData)



          //...


          use globals



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function()
          ,
          set: function(dataObj)
          window.gridData = dataObj








          share|improve this answer




























          • My question is about detecting whether the user comes to the page or rather comes back to the page. Let's say we have a few pages: P1, P2, P3, P4. When user navigates from P1 to P2 then P2 starts a new flow. When they go on to P3 and then back to P2 then I'd like to be notified they came back.

            – Pawel
            Mar 29 at 10:43











          • Oh ok - is this more what you are looking for: vuejs.org/v2/api/#keep-alive ?

            – Estradiaz
            Mar 29 at 10:57











          • Keep alive doesn't store the page state when you change the component. That's what happens when I navigate to another page. Anyway it's not what I'm after. I just want to be notified when the user moves back to a page in the browsing history.

            – Pawel
            Mar 29 at 11:53












          • I added some sketch of a history component, that will trigger a @visited event

            – Estradiaz
            Mar 29 at 12:15












          • Thanks for your effort. Let's say we've got Link, Page1 (it's got your code), Page2. By clicking Link the user navigates to Page1 then navigates to Page2 and then comes back to Page1. That's fine, your code works. However it fails when the user follows Link, Page1, Page2, Link, Page1 because it says the user has come back to P1 which is not true.

            – Pawel
            Mar 29 at 13:36













          0














          0










          0









          HISTORY COMPONENT



          // component ...
          // can error and only serves the purpose of an idea
          data()
          return
          history: []

          ,
          watch:
          fullRoute: function()
          this.history.push(this.fullRoute);
          this.$emit('visited', this.visited);

          ,
          computed:
          fullRoute: function()
          return this.$route.fullPath
          ,
          visited: function()
          return this.history.slice(-1).includes(this.fullRoute)




          the data way



          save the information in the browser



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function()
          return JSON.parse(local.storage.gridData)
          ,
          set: function(dataObj)
          local.storage.gridData = JSON.stringify(dataObj)



          //...


          use statemanagement



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function() ,
          set: function(dataObj)
          this.$store.dispatch("saveGrid", gridData)



          //...


          use globals



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function()
          ,
          set: function(dataObj)
          window.gridData = dataObj








          share|improve this answer
















          HISTORY COMPONENT



          // component ...
          // can error and only serves the purpose of an idea
          data()
          return
          history: []

          ,
          watch:
          fullRoute: function()
          this.history.push(this.fullRoute);
          this.$emit('visited', this.visited);

          ,
          computed:
          fullRoute: function()
          return this.$route.fullPath
          ,
          visited: function()
          return this.history.slice(-1).includes(this.fullRoute)




          the data way



          save the information in the browser



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function()
          return JSON.parse(local.storage.gridData)
          ,
          set: function(dataObj)
          local.storage.gridData = JSON.stringify(dataObj)



          //...


          use statemanagement



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function() ,
          set: function(dataObj)
          this.$store.dispatch("saveGrid", gridData)



          //...


          use globals



          // component ...
          // can error and only serves the purpose of an idea
          computed:
          gridData:
          get: function()
          ,
          set: function(dataObj)
          window.gridData = dataObj









          share|improve this answer















          share|improve this answer




          share|improve this answer








          edited Mar 29 at 12:13

























          answered Mar 29 at 10:28









          EstradiazEstradiaz

          1,3121 gold badge2 silver badges13 bronze badges




          1,3121 gold badge2 silver badges13 bronze badges















          • My question is about detecting whether the user comes to the page or rather comes back to the page. Let's say we have a few pages: P1, P2, P3, P4. When user navigates from P1 to P2 then P2 starts a new flow. When they go on to P3 and then back to P2 then I'd like to be notified they came back.

            – Pawel
            Mar 29 at 10:43











          • Oh ok - is this more what you are looking for: vuejs.org/v2/api/#keep-alive ?

            – Estradiaz
            Mar 29 at 10:57











          • Keep alive doesn't store the page state when you change the component. That's what happens when I navigate to another page. Anyway it's not what I'm after. I just want to be notified when the user moves back to a page in the browsing history.

            – Pawel
            Mar 29 at 11:53












          • I added some sketch of a history component, that will trigger a @visited event

            – Estradiaz
            Mar 29 at 12:15












          • Thanks for your effort. Let's say we've got Link, Page1 (it's got your code), Page2. By clicking Link the user navigates to Page1 then navigates to Page2 and then comes back to Page1. That's fine, your code works. However it fails when the user follows Link, Page1, Page2, Link, Page1 because it says the user has come back to P1 which is not true.

            – Pawel
            Mar 29 at 13:36

















          • My question is about detecting whether the user comes to the page or rather comes back to the page. Let's say we have a few pages: P1, P2, P3, P4. When user navigates from P1 to P2 then P2 starts a new flow. When they go on to P3 and then back to P2 then I'd like to be notified they came back.

            – Pawel
            Mar 29 at 10:43











          • Oh ok - is this more what you are looking for: vuejs.org/v2/api/#keep-alive ?

            – Estradiaz
            Mar 29 at 10:57











          • Keep alive doesn't store the page state when you change the component. That's what happens when I navigate to another page. Anyway it's not what I'm after. I just want to be notified when the user moves back to a page in the browsing history.

            – Pawel
            Mar 29 at 11:53












          • I added some sketch of a history component, that will trigger a @visited event

            – Estradiaz
            Mar 29 at 12:15












          • Thanks for your effort. Let's say we've got Link, Page1 (it's got your code), Page2. By clicking Link the user navigates to Page1 then navigates to Page2 and then comes back to Page1. That's fine, your code works. However it fails when the user follows Link, Page1, Page2, Link, Page1 because it says the user has come back to P1 which is not true.

            – Pawel
            Mar 29 at 13:36
















          My question is about detecting whether the user comes to the page or rather comes back to the page. Let's say we have a few pages: P1, P2, P3, P4. When user navigates from P1 to P2 then P2 starts a new flow. When they go on to P3 and then back to P2 then I'd like to be notified they came back.

          – Pawel
          Mar 29 at 10:43





          My question is about detecting whether the user comes to the page or rather comes back to the page. Let's say we have a few pages: P1, P2, P3, P4. When user navigates from P1 to P2 then P2 starts a new flow. When they go on to P3 and then back to P2 then I'd like to be notified they came back.

          – Pawel
          Mar 29 at 10:43













          Oh ok - is this more what you are looking for: vuejs.org/v2/api/#keep-alive ?

          – Estradiaz
          Mar 29 at 10:57





          Oh ok - is this more what you are looking for: vuejs.org/v2/api/#keep-alive ?

          – Estradiaz
          Mar 29 at 10:57













          Keep alive doesn't store the page state when you change the component. That's what happens when I navigate to another page. Anyway it's not what I'm after. I just want to be notified when the user moves back to a page in the browsing history.

          – Pawel
          Mar 29 at 11:53






          Keep alive doesn't store the page state when you change the component. That's what happens when I navigate to another page. Anyway it's not what I'm after. I just want to be notified when the user moves back to a page in the browsing history.

          – Pawel
          Mar 29 at 11:53














          I added some sketch of a history component, that will trigger a @visited event

          – Estradiaz
          Mar 29 at 12:15






          I added some sketch of a history component, that will trigger a @visited event

          – Estradiaz
          Mar 29 at 12:15














          Thanks for your effort. Let's say we've got Link, Page1 (it's got your code), Page2. By clicking Link the user navigates to Page1 then navigates to Page2 and then comes back to Page1. That's fine, your code works. However it fails when the user follows Link, Page1, Page2, Link, Page1 because it says the user has come back to P1 which is not true.

          – Pawel
          Mar 29 at 13:36





          Thanks for your effort. Let's say we've got Link, Page1 (it's got your code), Page2. By clicking Link the user navigates to Page1 then navigates to Page2 and then comes back to Page1. That's fine, your code works. However it fails when the user follows Link, Page1, Page2, Link, Page1 because it says the user has come back to P1 which is not true.

          – Pawel
          Mar 29 at 13:36




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407463%2fhow-to-detect-the-user-comes-back-to-a-page-rather-than-starts-browsing-it%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown









          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript