繁体   English   中英

与Redux和Router反应-不渲染组件

[英]React with Redux and Router - not rendering component

我不明白为什么组件Sample根本无法渲染。 网址更改,控制台中没有错误,但是未安装组件。 无论是功能组件还是React类。 以及为什么正确显示带有URL“ / thisworks”的内联组件。 我在这里做错了什么?

index.jsx:

render(
    <Provider store={store}>
        <Root />
    </Provider>,
    document.getElementById("root")
);

root.js:

const Root = () => (
    <div>
        <BrowserRouter>
            <Switch>
// routes below work fine
                <Route path="/login" component={LoginPage} />
                <Route path="/" component={App} />
            </Switch>
        </BrowserRouter>
        <DevTools />
    </div>
)

App.js:

class App extends React.Component {
    render() {
        return (
            <div>
                <NavMenu />
                <Switch>
                    <Route path="/thisworks" render={(props) => {
                        return (<div>This works!</div>);
                    }} />
                    <Route path="/sample" Component={Sample} /> // not working - not rendering component Sample
                    <Redirect from="/" to="/sample" />
                </Switch>
            </div>
        );
    }
}

const mapStateToProps = (state, ownProps) => ({})    
const mapDispatchToProps = (dispatch) => ({})    
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(App))

Sample.jsx:

const Sample = (props) => {
    return (
        <div>
            Sample!
        </div>
    );
}
export default Sample;

也许component而不是Component

<Route path="/sample" component={Sample} />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM