【发布时间】:2019-07-25 02:55:47
【问题描述】:
我有一个 <Routes> 组件,它只呈现一个 <Dashboard> 组件。当我尝试获取 <BillingCycle> 组件时,没有发生同样的事情。当我在浏览器中输入可能获取 BillingCycle' 页面的 URL 时,Billing Cycles 内容没有出现。继续显示仪表板内容。我错了什么?谢谢你。
导入'../common/template/dependencies' 从“反应”导入反应
这里是导入 Routes 组件的父组件。
import Routes from './Routes'
export default (props) => (
<div className='wrapper'>
<div className='content-wrapper'>
<Routes />
</div>
</div>
)
这里是成功出现在这些 url 中的仪表板组件:http://localhost:8080 和 http://localhost:8080/#/
import React from 'react'
export default props => (
<div>
<h1>Dashboard</h1>
</div>
)
这里是当我输入它的 url 时没有出现的 billingCycle 组件: http://localhost:8080/#/billingCycles
import React from 'react'
export default props => {
return (
<h1>Ciclo de pagamentos</h1>
)
}
这里是路由组件:
import React from 'react'
import { BrowserRouter as Router, Route, Redirect, Switch } from 'react-router-dom';
import Dashboard from '../dashboard/Dashboard'
import BillingCycle from '../billingCycle/BillingCycle'
export default props => (
<Router>
<Switch>
<Route exact path='#/billingCycles' component={BillingCycle} />
<Route exact path='/' component={Dashboard} />
<Redirect from='*' to='/' />
</Switch>
</Router>
)
【问题讨论】:
-
为了做到这一点,您必须使用服务器端渲染或也称为同构。