【发布时间】:2017-07-29 16:36:54
【问题描述】:
我正在重写一个 ASP.NET MVC 应用程序以在 TypeScript 中使用 React 和 Redux。对于路由,我使用的是 React Router。该站点使用根参数来标识客户的组织。
示例; www.oursite.com/:organizationId 带有深层链接,例如 www.oursite.com/:organizationId/overview 或 www.oursite.com/:organizationId/account/:accountId
我已经如下配置了 React 路由器
import * as React from 'react';
import { Router, Route, IndexRoute, HistoryBase } from 'react-router';
import { Layout } from './components/Layout';
import Home from './components/Home';
import OverView from './components/OverView';
import Account from './components/Account';
export default <Route path='/:organizationId' component={ Layout }>
<IndexRoute components={{ body: Home }} />
<Route path='overview' components={{ body: OverView }} />
<Route path='account/:accountId' components={{ body: Account }} />
</Route>;
这可行,但页面上的任何链接组件都不起作用,因为应用程序/页面的根仍然是 /。
例如
<Link to={'/overview'} activeClassName='active' />
在帐户控制链接上指向 www.oursite.com/overview,而不是 www.oursite.com/:organizationId/overview。
有没有办法配置 React Router 以将 /:organizationId/ 视为根?
【问题讨论】:
标签: reactjs typescript react-router react-redux-form