React Router仅使用查询参数导航

时间:2019-05-19 07:04:49

标签: javascript reactjs

我正在尝试创建如下所示的URL结构:

/app?page=home
/app?page=posts
/app?page=post&post_id=123

(而不是/app/home/app/posts/app/post/123 ...)

我这样做:

<Router basename="/app">
  <div>
    <Link to="?page=home">Home</Link>
    <Link to="?page=posts">Posts</Link>
    <Link to="?page=posts&post_id=123">Post 123</Link>

    <Route path="?page=home" component={Home} />
    <Route path="?page=posts" component={Posts} />
    <Route path="?page=post&post_id=:id" component={Post} />
  </div>
</Router>

但是它似乎不起作用,我可以导航(更改URL),但是Route组件无法呈现

0 个答案:

没有答案