
importReactfrom'react'import{render}from'react-dom'constAbout=React.createClass({/**/})constInbox=React.createClass({/**/})constHome=React.createClass({/**/})constApp=React.createClass({getInitialState(){return{route:window.location.hash.substr(1)}},componentDidMount(){window.addEventListener('hashchange',()=>{this.setState({route:window.location.hash.substr(1)})})},render(){letChildswitch(this.state.route){case'/about':Child=Aboutbreakcase'/inbox':Child=Inboxbreakdefault:Child=Home}return(AppAboutInbox)}})render(,document.body)React.js在服务端渲染的好处:
支持seo关键字收录
用户访问不需要等待过长的loading动画 支持更多的后端如nodejs代码模板支持 支持
同构Isomorphic 用户进行交互的时候,有可能会比原生的响应快一些,前提是你做了一些优化避免了浪费性能的重复渲。
评论列表(0条)