# ログイン画面の作成4

次にリンクを貼りましょう。

ヘッダーのロゴをクリックした際にTopページに、右上のログインをクリックした際にログインページに遷移するようにしましょう。

その際は、`react-router-dom`の`Link`タグを使用します。`Link`タグは`to`に遷移したいurlを渡すことで、そのurlに遷移することができます。

<pre class="language-tsx" data-title="templates/NotLoginLayout.tsx◎"><code class="lang-tsx"><strong>import { Link, Outlet } from "react-router-dom"
</strong>
export const NotLoginLayout = () => {
  return (
    &#x3C;div className="relative">
      &#x3C;header className="bg-white leading-[50px] fixed top-0 left-0 right-0">
        &#x3C;div className="container mx-auto flex justify-between">
<strong>          &#x3C;p className="logo">
</strong><strong>            &#x3C;Link to="/">スケジュール管理APP&#x3C;/Link>
</strong><strong>          &#x3C;/p>
</strong>          &#x3C;nav>
            &#x3C;ul className="flex gap-5 text-lime-800">
              &#x3C;li>ご利用方法&#x3C;/li>
<strong>              &#x3C;li>
</strong><strong>                &#x3C;Link to="/login">ログイン&#x3C;/Link>
</strong><strong>              &#x3C;/li>
</strong>            &#x3C;/ul>
          &#x3C;/nav>
        &#x3C;/div>
      &#x3C;/header>
      &#x3C;main className="pt-[50px] bg-gradient-to-r from-lime-100 to-lime-200 h-screen flex flex-col justify-center items-center">
        &#x3C;Outlet />
      &#x3C;/main>
    &#x3C;/div>
  );
}
</code></pre>

画面にて画面遷移することが確認できるかと思います。

次に、Topページ中央のログインボタンを押した際にログインページに遷移できるようにします。

その前にPrimaryBtnコンポーネントにて`onClick`を受け取れるようにします。

<pre class="language-tsx" data-title="atom/PrimaryBtn.tsx◎"><code class="lang-tsx">import { ReactNode } from "react";

type PropsType = {
<strong>  onClick: () => void
</strong>  children: ReactNode
}

<strong>export const PrimaryBtn = ({ onClick, children }: PropsType) => {
</strong>  return (
<strong>    &#x3C;button className="bg-lime-800 text-white p-4 text-lg rounded-lg" onClick={onClick}>
</strong>      {children}
    &#x3C;/button>
  );
};

</code></pre>

そして、`react-router-dom`の`useNavigate`というhooksを使用します。

その`useNavigate`の`navigate`という関数で引数に遷移したいurlを渡すことで、そのurlに遷移することができます。

<pre class="language-tsx" data-title="pages/TopPage.tsx◎"><code class="lang-tsx"><strong>import { useNavigate } from "react-router-dom"
</strong>import { PrimaryBtn } from "../atoms/PrimaryBtn"

export const TopPage = () => {
<strong>  const navigate = useNavigate()
</strong><strong>
</strong>  return (
    &#x3C;div className="text-center">
      &#x3C;h1 className="text-7xl logo">スケジュール管理APP&#x3C;/h1>
      &#x3C;p className="pt-[10vh] text-5xl">
        お互いのスケジュールを管理するアプリです
      &#x3C;/p>
      &#x3C;div className="pt-[20vh]">
<strong>        &#x3C;PrimaryBtn onClick={() => navigate("/login")}>ログイン&#x3C;/PrimaryBtn>
</strong>      &#x3C;/div>
    &#x3C;/div>
  );
}
</code></pre>

また、`LoginPage.tsx`の`PrimaryBtn`のonClickには`() => null`を渡しておきます。

<pre class="language-tsx" data-title="pages/LoginPage.tsx◎"><code class="lang-tsx">import { Input } from "../atoms/Input";
import { PrimaryBtn } from "../atoms/PrimaryBtn";

export const LoginPage = () => {
  return (
    &#x3C;div className="w-[500px] bg-white rounded-lg shadow-lg py-10">
      &#x3C;form className="flex flex-col justify-center items-center gap-10">
        &#x3C;h1 className="text-3xl text-lime-800 font-bold text-center">
          ログイン
        &#x3C;/h1>
        &#x3C;div className="w-[80%]">
          &#x3C;Input
            type="text"
            placeholder="email"
          />
        &#x3C;/div>
        &#x3C;div className="w-[80%]">
          &#x3C;Input
            type="password"
            placeholder="password"
          />
        &#x3C;/div>
<strong>        &#x3C;PrimaryBtn onClick={() => null}>ログイン&#x3C;/PrimaryBtn>
</strong>      &#x3C;/form>
    &#x3C;/div>
  );
};
</code></pre>

ここまでの作業をcommitしましょう。

```bash
git add .
```

```bash
git commit
```

commitメッセージは

```
feat: トップページとログインページへのリンクを追加
```

としましょう。

ではログインページの作成が完了したので、GitHubにpushしましょう。

```basic
git push origin feature/login-page
```

これでGitHubのリポジトリのページにいき、main <- feature/login-pageのPRを作成しましょう。

PRのタイトルは

```
feat: ログイン画面を作成
```

としましょう。

作成したら自身で`Merge pull request`を押してmergeしましょう。

mergeが完了したらWarpに戻り、mainをpullしましょう。

```bash
git switch main
```

```bash
git pull origin main
```
