New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to recreate page on same link? #2285

Closed
Clemens-B opened this Issue Nov 29, 2017 · 7 comments

Comments

Projects
None yet
4 participants
@Clemens-B
Copy link

Clemens-B commented Nov 29, 2017

Hello,

I have a fixed navigation bar and I want to recreate (without reloading the whole App) the page, if the users clicks the same link again. I tried to work with the prop key on the nuxt tag, but this doesn't work.

<div class="navigation-bar">
   <button v-on:click.native="$router.push('/news')">News</button>
</div>

<nuxt :key="$route.fullPath"></nuxt> 

See also here: Stackoverflow

This question is available on Nuxt.js community (#c2000)
@clarkdo

This comment has been minimized.

Copy link
Member

clarkdo commented Nov 30, 2017

  1. native only supports binding on components, https://vuejs.org/v2/api/#v-on
  2. Nuxt has created key of <nuxt> by value of $route.path, if you want to change it, use :nuxtChildKey='...' on <nuxt>

If you wan to reload pages, try:

<button @click="$router.go({path:'/news', force: true})">News</button>
@Clemens-B

This comment has been minimized.

Copy link

Clemens-B commented Dec 1, 2017

Hello clarkdo,

thanks for your answer. $router.go reloads the whole page, but I want to initialise a new instance of the page without reloading the webapp.

:nuxtChildKey sounds promising and I already gave it a first shoot by applying a unique ID like Date.now() to :nuxtChildKey but this doesn't seem to work.

For now, I routing to a loading page before redirecting to news again.

@clarkdo

This comment has been minimized.

Copy link
Member

clarkdo commented Dec 1, 2017

You can have a look at vuejs/vue-router#296, canReuse or re-fetch the data may help you

@clarkdo clarkdo closed this Dec 2, 2017

@hartmut-co-uk

This comment has been minimized.

Copy link
Contributor

hartmut-co-uk commented Jun 4, 2018

@Clemens-B you're probably past that issue, but everyone ending up here.. -> have a look at $forceUpdate()

<template>
  <div id="app">
    <nuxt ref="page"/>
    ...
</template>

<script>
    ...
    this.$refs.page.$forceUpdate()
    ...
</script>

works like a charm for me, no 'hard' page reload, calling everything, e.g. fetch & asyncData, too..

Edit:
For completion, the actual js part even includes sth like

if (this.$router.currentRoute.path === to) {
    this.$refs.page.$forceUpdate()
} else {
    this.$router.push(to)
}
@benwinding

This comment has been minimized.

Copy link

benwinding commented Oct 9, 2018

Any new solutions to this yet?

@benwinding

This comment has been minimized.

Copy link

benwinding commented Oct 16, 2018

I found that as described above this solves the issue.

<nuxt :key="$route.fullPath" />

And allows any page to render again even if it's a link to itself with different query parameters

@lock

This comment has been minimized.

Copy link

lock bot commented Nov 15, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 15, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.