File tree Expand file tree Collapse file tree 3 files changed +41
-5
lines changed Expand file tree Collapse file tree 3 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ module.exports = {
17
17
source : "/api/movies" ,
18
18
destination : `https://api.themoviedb.org/3/movie/popular?api_key=${ API_KEY } ` ,
19
19
} ,
20
+ {
21
+ source : "/api/movies/:id" ,
22
+ destination : `https://api.themoviedb.org/3/movie/:id?api_key=${ API_KEY } ` ,
23
+ } ,
20
24
] ;
21
25
} ,
22
26
} ;
Original file line number Diff line number Diff line change 1
- import { useEffect , useState } from "react" ;
1
+ import Link from "next/link" ;
2
+ import { useRouter } from "next/router" ;
2
3
import Seo from "../components/Seo" ;
3
4
4
5
export default function Home ( { results } ) {
6
+ const router = useRouter ( ) ;
7
+ const onClick = ( id , title ) => {
8
+ router . push (
9
+ {
10
+ pathname : `/movies/${ id } ` ,
11
+ query : {
12
+ title,
13
+ } ,
14
+ } ,
15
+ `/movies/${ id } `
16
+ ) ;
17
+ } ;
5
18
return (
6
19
< div className = "container" >
7
20
< Seo title = "Home" />
8
21
{ results ?. map ( ( movie ) => (
9
- < div className = "movie" key = { movie . id } >
22
+ < div
23
+ onClick = { ( ) => onClick ( movie . id , movie . original_title ) }
24
+ className = "movie"
25
+ key = { movie . id }
26
+ >
10
27
< img src = { `https://image.tmdb.org/t/p/w500${ movie . poster_path } ` } />
11
- < h4 > { movie . original_title } </ h4 >
28
+ < h4 >
29
+ < Link
30
+ href = { {
31
+ pathname : `/movies/${ movie . id } ` ,
32
+ query : {
33
+ title : movie . original_title ,
34
+ } ,
35
+ } }
36
+ as = { `/movies/${ movie . id } ` }
37
+ >
38
+ < a > { movie . original_title } </ a >
39
+ </ Link >
40
+ </ h4 >
12
41
</ div >
13
42
) ) }
14
43
< style jsx > { `
Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ import { useRouter } from "next/router";
2
2
3
3
export default function Detail ( ) {
4
4
const router = useRouter ( ) ;
5
- console . log ( router ) ;
6
- return "detail" ;
5
+ return (
6
+ < div >
7
+ < h4 > { router . query . title || "Loading..." } </ h4 >
8
+ </ div >
9
+ ) ;
7
10
}
You can’t perform that action at this time.
0 commit comments