1
1

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.

いなたつAdvent Calendar 2019

Day 22

Reactで投稿のIDを取得する

Last updated at Posted at 2019-12-22

はじめに

いなたつアドカレの二十二日目の記事です。

もうすぐ終わりですね。。。

今回はReactでURLから投稿などのIDを取得する方法の備忘録です。

じっそー

App.js
import React from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom'

function App() {
  return (
    <Router>

        <Route exact path='/:id' component={Hoge} />
    </Router>

  );
}


export default App;

/:idのURLでHogeのコンポーネントというRouteの定義ができました。

const id = props.match.params.id

Hogeのコンポーネントで上のようにすることで、idを使用できます

このidを使ってAPiを叩くなりしましょ

1
1
1

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?