【发布时间】:2021-05-05 10:00:32
【问题描述】:
我有一个从 url 接收自定义 id 并根据该 id 获取数据的页面。
例如:
let params = useParams();
useEffect(() => {
axios
.get("http://localhost:8000/api/profile/" + params.id)
.then((response) => {
setUsername(response.data.username);
})
.catch((err) => console.log(err));
}, []);
问题是参数显示在url中,我想隐藏它,怎么做?
输出的现有路由例如http://localhost:8000/customize/9:
<Route path="/customize/:id" component={Home} />
我想在网址中包含什么:
http://localhost:8000/customize/
【问题讨论】:
-
如果你不希望参数出现在 URL 中,为什么要把它放在路由中?像这样从路径中删除它
path="/customize"no ? -
@Marc Charpentier 我想将 id 传递给页面,以便可以根据该 id 加载元素。如果有其他选择,我会欢迎的。
-
在下面查看我的答案
标签: reactjs react-router react-router-dom