反应布局不好看

时间:2017-02-19 14:25:23

标签: reactjs react-router react-redux material-ui

我正在开发一个反应应用程序,其中我们有顶部的标题,侧面导航栏和页脚通常每个应用程序都有它。我的应用程序布局看起来不太好。顶部标题很好,但页面内容总是左侧。 下面是我的index.js代码

import React ,{ Component } from 'react';
import {render} from 'react-dom';
import { Provider } from 'react-redux';
import { Router, Route, browserHistory, IndexRoute } from 'react-router';
import routes from './routes.jsx';
import injectTapEventPlugin from 'react-tap-event-plugin';
import theme from './material_ui_raw_theme_file.jsx';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import NotFoundPage from './staticComponents/NotFoundPage.jsx';
import configureStore from './store/configureStore.jsx';
import { syncHistoryWithStore, routerReducer} from 'react-router-redux';
import App from './components/App.jsx';
import Home from './components/home.jsx';
import ProjectIndex from './pages/projectIndex.jsx';
import SignIn from './components/SignInForm.jsx';

//for React Developer Tools
window.React = React;

const store = configureStore();
const history = syncHistoryWithStore(browserHistory, store)

injectTapEventPlugin();

render(
  <MuiThemeProvider muiTheme={theme}>
    <Provider store={store}>
    <Router history={history}>
      <Route path="/" component={App}>
        <IndexRoute component = {Home} />
        <Route path="/home" component={Home} />
        <Route path="/project" component={ProjectIndex} />
        <Route path="/signin" component={SignIn} />
        <Route path="*" component={NotFoundPage}/>
      </Route>  
    </Router>
  </Provider>
  </MuiThemeProvider>
  , document.getElementById('body')

);

App.jsx代码是: -

class App extends Component {
  constructor(props){
    super(props)
     this.state = {
      logged: false,
    };
  }
  render() {

    return (
        <div className="page_container">
        <div>
        <AppBar
          title="Issue Tracker"
          iconElementRight={<Logged />}
        />
        </div>
        <div>     
          {this.props.children}
         </div>
      </div>

    );
  }
}

export default App;

Home.jsx代码是: -

import React ,{Component} from 'react';
class Home extends Component{
  constructor(props){
    super(props)
  }
  render(){
    return(
      <div>
        <h1>Hi this is home</h1>
      </div>
    )
  }
}

export default Home;

和输出是 enter image description here

任何帮助都会很棒。 感谢

1 个答案:

答案 0 :(得分:1)

您需要在注入props.children的div中添加样式,您可以尝试这样的事情:

class App extends Component {
  constructor(props){
    super(props)
     this.state = {
      logged: false,
    };
  }
  render() {

    return (
        <div className="page_container">
        <div>
        <AppBar
          title="Issue Tracker"
          iconElementRight={<Logged />}
        />
        </div>
        <div className="main-content-wrapper">     
          {this.props.children}
         </div>
      </div>

    );
  }
}

export default App;

在你的CSS中:

.main-content-wrapper {
    width: 700px;
    margin: auto;
}

.main-content-wrapper {
    padding: 20px;
}

现在可以根据自己的喜好设计它。