Skip to content
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

Reload page on specific routes #1589

Closed
seahindeniz opened this issue Oct 27, 2022 · 2 comments
Closed

Reload page on specific routes #1589

seahindeniz opened this issue Oct 27, 2022 · 2 comments

Comments

@seahindeniz
Copy link

seahindeniz commented Oct 27, 2022

What problem does this feature solve?

Some pages may need to page reload when their router link gets clicked.
I have Google'd it and search older issues, but found nothing that suggests an organic way to achieve it.

What does the proposed API look like?

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "home",
      component: HomeView,
    },
    {
      path: "/about",
      name: "about",
      component: () => import("../views/AboutView.vue"),
    },
    {
      path: "/csp-1",
      name: "csp-1",
      component: () => import("../views/CSP-1.vue"),
      // new optional property reload/reloadOnSwitch/reloadOnRedirect etc.
      reload: true
    },
  ],
});

I've tried an alternative solution which works, but it doesn't look organic

<script setup lang="ts">
import { RouterLink, RouterView, useRouter } from "vue-router";

const router = useRouter();

const redirectWithReload = async (path: string): Promise<void> => {
  await router.push({ path });
  router.go(0);
};
</script>

<template>
  <header class="my-7">
    <nav>
      <RouterLink to="/">Home (SPA)</RouterLink>
      <RouterLink to="/about">About (SPA)</RouterLink>
      <a
        href="/csp-1"
        :class="{
          'router-link-active router-link-exact-active':
            router.currentRoute.value.name === 'csp-1',
        }"
        @click="redirectWithReload('csp-1')"
        >CSP 1 (reload)</a
      >
    </nav>
  </header>

  <RouterView />
</template>
@posva
Copy link
Member

posva commented Oct 27, 2022

Duplicate of #1257

@posva posva marked this as a duplicate of #1257 Oct 27, 2022
@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Oct 27, 2022
@posva
Copy link
Member

posva commented Oct 27, 2022

Please, search existing issues and pull requests before opening issues, it saves maintainers a lot of time 🙏

@vuejs vuejs locked and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants