0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vue3で特定のページ遷移を制限する方法

Last updated at Posted at 2024-01-18

はじめに

ブラウザの戻るボタンで前のページに戻って欲しくない場面がありました。その時の解決方法を記録します。

解決方法

Navigation Guardを使いました。
以下は支払いページから(/payment)から支払いページ(/payment-complete) に戻らないように制限する例です。

index.ts
router.beforeEach((to, from, next) => {
  if (from.path === "/payment" && to.path === "/payment-complete") {
    next(false);
  } else {
    next();
  }
});
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?