【发布时间】:2016-11-06 21:04:53
【问题描述】:
假设我的应用的基本网址是 example.com/app
是否可以在 react-router 中设置基本路由,而不是将所有路由都写成
/app/a
/app/b
/app/c
我可以将它们指定为
a
b
c
我尝试了在docs 中找到的以下示例,但它不起作用(页面不会显示任何内容)。也许是因为我使用的是 react-router@3.0.0-alpha.1,或者我做错了什么。
import { useRouterHistory } from 'react-router'
import { createHistory } from 'history'
const history = useRouterHistory(createHistory)({
basename: '/app'
})
const Root = ({store}) => (
<Provider store={store}>
<Router history={history}>
<Route path='/' component={App}>
...
</Route>
</Router>
</Provider>
)
【问题讨论】:
-
问题解决了吗?如果是,请发布答案。
-
@Learner 不。我放弃并开始输入完整的路线,实际上发现它更干净。
-
真的吗?没有简单的解决方案吗?我已经搜索并尝试了一些想法,但没有任何运气(但我是新手)。
标签: react-router