react
我使用, react-router
,创建了一个应用程序react-redux
,connected-react-router
并且具有以下结构:
- app
- admin
- category
- categoryList
- categoryAdd
我的想法是执行以下应用程序流程:
/admin -> /admin/category -> /admin/category/add
但由于某种原因,我看不到CategoryAdd
渲染的最后一个组件()。
代码(沙盒链接在最后):
index.js
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { Route, Switch, Link } from "react-router-dom";
import { ConnectedRouter } from "connected-react-router";
import configureStore, { history } from "./configureStore";
import AdminPage from "./AdminPage";
import Category from "./Category";
const store = configureStore(/* provide initial state if any */);
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<>
<Link to="/admin/category">Category</Link>
<Switch>
<Route exact path="/admin" component={AdminPage} />
<Route exact path="/admin/category" component={Category} />
</Switch>
</>
</ConnectedRouter>
</Provider>,
document.getElementById("root")
);
管理页面.js
import React from "react";
import { Link } from "react-router-dom";
export default function AdminPage() {
return (
<div style={{ border: "1px solid black", margin: 20 }}>
<div>AdminPage</div>
<Link to="/admin/category">Catgory page link</Link>
</div>
);
}
类别.js
import React from "react";
import { Route, Switch } from "react-router-dom";
import { withRouter } from "react-router-dom";
import CategoryList from "./CategoryList";
import CategoryAdd from "./CategoryAdd";
function Category() {
return (
<Switch>
<Route path={`/admin/category`} render={() => <CategoryList />} />
<Route path={`/admin/category/add`} render={() => <CategoryAdd />} />
</Switch>
);
}
export default withRouter(Category);
类别列表.js
import React from "react";
import { Link } from "react-router-dom";
export default function CategoryList() {
return (
<div style={{ border: "1px solid black", margin: 20 }}>
CategoryTable <Link to="/admin/category/add">Add</Link>
</div>
);
}
CategoryAdd.js
export default function Add() {
return <div style={{ border: "1px solid black", margin: 20 }}>Add Page</div>;
}