【发布时间】:2020-12-05 17:07:19
【问题描述】:
我正在尝试了解如何使用 react router 6 和 useNavigate,但不知道如何获取当前路径名。
使用 useHistory 我可以使用history.location.pathname 来获取当前网址。但是如何使用 useNavigate 做同样的事情呢?
import React, {useState} from 'react'
import styed from 'styled-components'
import { useNavigate } from 'react-router-dom'
import { MovieState } from '../movieState'
export const MovieDetail = () => {
let navigate = useNavigate();
const [movies, setMovies] = useState(MovieState)
const [movie, setMovie] = useState(null)
//const url = navigate.location.pathname;
return (
<div>
<h1>MovieDetail</h1>
</div>
)
}
【问题讨论】: