# /login へリダイレクトする初期ページを無効化

**URL:** https://meta.discourse.org/t/disable-initial-page-that-re-directs-to-login/400773
**Category:** Development
**Tags:** login
**Created:** [2026 年 4 月 16 日午前 8:40 UTC](https://meta.discourse.org/t/disable-initial-page-that-re-directs-to-login/400773 "2026-04-16T08:40:01Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Ethsim2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethsim2/32/522255_2.png) [@Ethsim2](https://meta.discourse.org/u/Ethsim2)
#### Post date: [2026 年 4 月 16 日午前 8:40 UTC](https://meta.discourse.org/t/disable-initial-page-that-re-directs-to-login/400773/1 "2026-04-16T08:40:01Z")

</div>

こんにちは

現在のページで表示される唯一の「ログイン」ボタンを押す必要を避けるため、現在、ゆっくりとしたリダイレクトを実装しています。

```js
import { apiInitializer } from "discourse/lib/api";

export default apiInitializer("1.0", (api) => {
  api.onPageChange((url) => {
    const user = api.getCurrentUser();

    let path = url?.startsWith("http") ? new URL(url).pathname : url;
    path = path?.replace(/\/+$/, "") || "/";

    const allowedAnonPaths = ["/login", "/privacy", "/tos", "/pub/about-this-forum", "/safe-mode", "/pub/accessibility-statement"];

    if (!user && !allowedAnonPaths.includes(path)) {
      window.location.href = "/login";
    }
  });
});

```

これは、リダイレクトしたくないパスを除外するものです。

* * *

これは理想的ではありませんが、現在は [https://physicswithethan.discourse.diy](https://physicswithethan.discourse.diy) で運用されています。

---

_[View the full topic](https://meta.discourse.org/t/disable-initial-page-that-re-directs-to-login/400773)._
