ReactJS;导航到一个动态的'数据生成的新页面?

时间:2016-12-02 04:44:28

标签: javascript reactjs

所以我有主页,它提供了很多项目。我的目标是让每个项目都可以点击,这会将您带到项目页面。需要注意的是很多项目(想想成千上万),所以我不打算为每个项目硬编码新页面;页面应该根据项目数据自动生成(从主页面传递,或从数据库中获取,并不重要)。

如果物品是书籍,我希望它看起来像这样; website.com/book/ReactJS For Dummies。现在书籍可以有不同的版本,这会影响页面上显示的数据,所以我需要传递一个额外的参数;类似于website.com/book/ReactJS For Dummies?edition=First_Edition

我已经尝试使用Google搜索reactJS解决方案,但它们似乎都涉及到现有网页的反应路由器和静态链接,而不是像这样的动态。

1 个答案:

答案 0 :(得分:0)

I would think that it would be better to have a unique key assigned to each book and then pass the key as a parameter, that way edition is a non issue, it's just another book. Kind of like barcodes. So you'd have

website.com/book/1 as React for Dummies 1st edition and then

website.com/book/2 as React for Dummies 2nd edition

Passing an ID as a parameter would be much simpler than book names with other queries attached