在我的应用程序中,我有一个API调用,它获取一些数据(对象数组),然后我在上下文中使用它,并在我的应用程序中共享它.我想要做的是使用一些数据,即对象值,并将其作为我的路由的前缀.API处理是通过Reaction-Query完成的.
我try 只访问该变量并按如下方式插入它:
const Routing: React.FunctionComponent = () => {
const { valueFromContext } = React.useContext(DataContext);
const basePrefix = valueFromContext?.name;
return (
<>
<BrowserRouter >
<Header />
<div className="App">
<Switch>
<Route exact path={["/", "/dashboard"]}>
<Redirect to={`/${basePrefix}/home`} />
</Route>
<Route exact path={[`/${basePrefix}/home`, "/"]} component={Home} />
<Route exact path={`/account/:id`} render={(props: RouteComponentProps<any>) => <Account {...props} />} />
<Route component={NotFound} />
</Switch>
</div>
</BrowserRouter>
</>
)
}
所以问题是这是不一致的,因为有时url返回为‘/unfined/home’并且显示404Not Found组件,所以我认为在响应完成之前就插入了路由?
你有什么 idea 吗?