14
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

React.jsでlocation.hrefを用いた外部URLへの遷移

Last updated at Posted at 2020-07-27

React.jsにてクリックイベント等でページ遷移させたい場合、window.location.hrefが利用できます。
Vue.jsの場合はwindowオブジェクトからの指定は不要だったため、備忘録として残します。

Googleへ遷移させたい場合
window.location.href = "https://google.com";
reactでの使用例
import React from "react";

function Google() {
  const redirectToGoogle = () => {
    window.location.href = "https://google.com";
  };
  return (
    <div>
      <div onClick={redirectToGoogle}>Googleへ</div>
    </div>
  );
}

export default Google;

14
11
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
14
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?