如何解决无法在组件内部获取参数并无法在React Hook组件中调用API
我是新来反应js的人。几天前,建立一个我部署在URL中的项目。该项目的流程是用户将收到一条消息,其中包含URL和该URL附带的pid。我的工作是获取pid,并在API中使用此pid调用home组件。 此URL将被提供给用户-http://booking.co/PIA=16sGykuT2g& 我的项目流程- Index.js-> App.js-> Routes.js(包含所有组件和布局的路由)。
routes.js
const Routes = () => {
var loc = window.location.href// I was trying to get the URL and store that bid in sessionstorage so that
//I can call it in dashboard page but it didn't work
var bid=loc.substring(
loc.lastIndexOf("=") + 1,loc.lastIndexOf("&"))
sessionStorage.setItem('bid',(bid))
var bid=(sessionStorage.bid)
console.log(bid)
return (
<Switch>
<Redirect
exact
from="/:pia"
to="/dashboard"
/>
<RouteWithLayout
component={DashboardView}
exact
layout={MainLayout}
path="/dashboard"
/>
<RouteWithoutLayout
component={UserListView}
exact
path="/users"
/>
</Switch>
)}
Dashboard.js
const Dashboard = props => {
const [amount,setamount]=useState('');
const [starttime,setstarttime]=useState('');
const [endtime,setendtime]=useState('');
const [currency,setcurrency]=useState('');
const { history } = props;
const [address,setaddress]=useState('');
var bid=(sessionStorage.bid)
console.log(bid)
console.log(props)
useEffect(()=>{
url: "/v1/userConfigByBID/"+bid,//getting this bid as nill
我想获取此PID参数并调用此API,同时将页面路径保持为'/ dashboard',而不是'/ dashboard /:pid'bcz,我试图将其设置为PWA,我想使用仅限'/ dashboard'路径
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。