获取ReactVR中的当前URL

时间:2018-01-20 04:13:41

标签: javascript reactjs express react-360

我试图通过网址将变量传递给ReactVR。

当我在console.log' window.location.pathname'在组件中,它会记录' http://localhost:3001/dddfe37b-926a-4adf-b40c-fda47bf3cf8b',

即使我的网址是' http://localhost:3001/vr",预期输出为' / vr'。

我就如何从express.js路由将变量传递到ReactVR提出任何建议。

代码是来自react-vr init的样板,但" state"和" componentDidMount()"

除外
import React from 'react';
import {
  AppRegistry,
  asset,
  Pano,
  Text,
  View,
} from 'react-vr';
import io from 'socket.io-client';

export default class view_react_vr extends React.Component {
  state = {
room: window.location.pathname
  }

  render() {
    return (
      <View>
        <Pano source={asset('chess-world.jpg')}/>
        <Text
          style={{
            backgroundColor: '#777879',
            fontSize: 0.8,
            fontWeight: '400',
            layoutOrigin: [0.5, 0.5],
            paddingLeft: 0.2,
            paddingRight: 0.2,
            textAlign: 'center',
            textAlignVertical: 'center',
            transform: [{translate: [0, 0, -3]}],
          }}>
          hello
        </Text>
      </View>
    )
  }

  componentDidMount() {
    let socket = io('http://localhost:3001/');

    // socket.emit('newRoom', this.state.room);
    socket.emit('updateState', this.state);
    socket.on('updateState', nextState => {
      console.log(nextState);
    });
  }

};

AppRegistry.registerComponent('view_react_vr', () => view_react_vr);

0 个答案:

没有答案