小编Lin*_*s J的帖子

在 next.js 中获取客户端的当前 url

因此,我正在开发一个 nodejs 应用程序,我将在该应用程序上运行我的新网站,并且我想为客户端的用户提供一种方式来显示不同的内容,并根据用户按下的内容重新呈现。我的想法是,例如,首先用户会看到“请先选择一个工具”,然后用户将在导航栏中选择一个工具,然后页面将重新呈现并显示在大屏幕中选择的工具,网址为例如然后更改 /admin/[ToolSelected]。

唯一的事情是我不知道如何实现这一目标。我在想,客户端代码可以检测到 url 是什么,并将其作为页面变量放置,然后该工具将根据页面变量的内容显示一个 IF 语句。

我的理论是否可行,或者如何以有效的方式实现这一目标?

这是我的主页代码:

// Including Navbar and css
import AdminLayout from '../comps/admin/adminLayout'

// the so called "tools" more will exist in the future
import Passform from '../comps/admin/tools/passform'


// Fetching the current url the user is on
var page = CURRENT_URL;


const jumbotron = {
  background: 'white'
}

const Admin = (page) => (

  <AdminLayout>

  <style global jsx>
  {
    `body {
      background: #eff0f3;
    }`
  }
  </style>
    <div className="jumbotron" style={jumbotron}>

    {(page == "passform") ? …
Run Code Online (Sandbox Code Playgroud)

express reactjs next.js

13
推荐指数
1
解决办法
1万
查看次数

标签 统计

express ×1

next.js ×1

reactjs ×1