小编Pra*_*GAR的帖子

如何在nextjs中用两个url链接同一页面

如果用户正在搜索特定城市,我想在页面名称之前的网址中显示城市名称,如果用户没有搜索特定城市,那么我想显示正常的网址。我们如何在 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 或功能。

reactjs server-side-rendering next.js

6
推荐指数
1
解决办法
6645
查看次数

标签 统计

next.js ×1

reactjs ×1

server-side-rendering ×1