javascript - React 中的子域路由
问题描述
我正在尝试使用 react-router v5 构建多用途网站以进行路由。对于普通路由,我们有类似的路由
本地主机:3000/帖子本地主机:3000/画廊
但对于其他一些情况,我想要子域让我们说博客。
blog.localhost:3000 // 渲染博客组件
或者
subdomain.localhost:3000 // 渲染一些组件。
现在,这也呈现与 localhost:3000 相同的组件。
那么,有什么办法可以让我做出反应吗?
当前路线如下所示。
function App() {
return (
<React.Fragment>
<React.Suspense fallback={<></>}>
<Router history={history}>
<Switch>
<Redirect exact from="/" to="/home" />
<Route exact path="/login" component={LoginPage} />
<ProtectedRoute exact={true} path="/profile" component={ProfilePage} />
<ProtectedRoute exact={true} path="/home" component={HomePage} />
<ProtectedRoute exact={true} path="/gallery/:subdomain" component={Gallery} />
<Route exact path="/gallery/post/:subdomain/:postid" component={SinglePostView} />
<Route component={PageNotFound} />
</Switch>
</Router>
</React.Suspense>
</React.Fragment>
);
}
解决方案
这是不可能的,React 不是 Web 服务器,React 是单页应用程序。您必须在该子域上托管另一个 React 应用程序。
推荐阅读
- vue.js - vuetify v-data-table 使用搜索功能搜索标题中未指示的项目属性
- php - php artisan cache clear PDOException 找不到驱动
- javascript - jsPDF 类型不存在属性“fromHTML”
- reactjs - 在正方形中反应 Konva 中心文本
- python - 亚马逊卖家中心 - SP-API - 获取货件标签
- ajax - 数据没有从 ajax 传递到控制器
- javascript - 如何用vue制作自定义轮播动画?
- laravel - 在一个视图中显示多个图像 laravel 7
- github-api - 从 github 下载最新的 git/git 版本
- kubernetes - kubelet 重启后,节点状态始终为 Ready,SchedulingDisabled