【发布时间】:2021-03-29 04:14:08
【问题描述】:
。我正在尝试使用动态路由和使用 React Link 标签移动到 url。问题是它更改了 url 但没有重新呈现 ui。当我使用锚标记或刷新页面时,它会呈现。我一直在尝试检测问题,但我目前陷入困境。我在下面实现了类似的东西,并且工作正常。
这是我的 App.js 的 sn-p
// Front end pages
if (isFrontEndPage()) {
return (
<Layout className="app-container">
<AppHeader />
<Layout>
<AppSidebar />
<Content className="app-content" breakpoint="lg">
<div className="container" style={{ minHeight: '100vh', padding: '10px' }} >
<Switch>
<Route path="/" exact component={Home} />
<Route path="/pricing" exact component={Pricing} />
<Route path="/features" exact component={Features} />
<Route path="/help/search/result.html" exact component={Post} />
<Route path="/help" exact render={(props) => <Redirect to="/p/help/invoices/index.html" /> } />
// I have a problem with this
<Route path="/p/:postType/:postCategoryUrlTitle/:postUrlTitle.html" component={Post} />
// I also have a problem with this
<Route path="/:postUrlTitle" component={Post} />
<Route component={NotFound} />
</Switch>
</div>
</Content>
</Layout>
<AppFooter />
</Layout>
)
}
return (
<Layout className="app-container">
<AppHeader />
<Layout>
<AppSidebar />
<Content className="app-content" breakpoint="lg">
<div className="container" style={{ minHeight: '100vh', padding: '10px' }} >
<Switch>
// The below similar links actually render accurately with dynamic routing
<PrivateRoute path="/posts/info-posts/new" component={InfoPost} />
<PrivateRoute path="/posts/info-posts/info-post/:infoPostId" component={InfoPost} />
<PrivateRoute path="/posts/info-posts" component={InfoPosts} />
<**************** OTHER PATHS ***********************>
<PrivateRoute component={NotFound} />
</Switch>
</div>
</Content>
</Layout>
<AppFooter />
</Layout>
);
}
export default App;
下面是我的 Index.js 的 sn-p
............
ReactDOM.render(
<BrowserRouter>
<AuthProvider>
<App />
</AuthProvider>
</BrowserRouter>,
document.getElementById('root')
);
【问题讨论】:
-
欢迎使用 stackoverflow。您应该将您的代码减少到一个最小的示例(即说明问题的最少代码)。这使得有人阅读它的可能性更大(即愿意花时间理解您的代码)。
-
感谢@kca 的评论。我会这样做的。
标签: javascript reactjs