如果用户正在搜索特定城市,我想在页面名称之前的网址中显示城市名称,如果用户没有搜索特定城市,那么我想显示正常的网址。我们如何在 Next Js 中实现这一点。
前任。
http://localhost:3000/Delhi/furniture
http://localhost:3000/furniture
Run Code Online (Sandbox Code Playgroud)
两个 url 应指向同一页面。
我尝试使用下一个/链接组件。
<Link href='/furniture' as={config.city ? config.city + '/furniture': 'furniture'}><a>Furniture</a></Link>
Run Code Online (Sandbox Code Playgroud)
Link 有两个 props href 和 as。使用 as 我们可以显示与实际 url 不同的 url,但如果您直接点击由 'as' 属性更改的 url,它将显示 404 页面未找到。我找不到任何可以实现上述目标的 porp 或功能。