进行登录会话后重定向到另一个URL

时间:2019-01-28 23:45:51

标签: react-native shopify

以下反应本机代码正在播放中。基本上,我想象中的代码将执行以下操作:

  • Webview发布用于购物的登录URL
  • 获得会话(现在登录会话附加到webview)后,我尝试重定向个人资料页面,以查看我是否登录。
  • 重定向后,我在个人资料页面或说登录无效的页面中。

我收到的问题是:

origWebviewInstance.source = {uri: 'https://google.com'};

似乎我无法重定向到google.com

此处的示例代码:

import React, {Component} from 'react';
import { WebView } from "react-native-webview";
// singleton
import { MyWebview } from './src/MyWebview/MyWebview';
import Config from "react-native-config";

const loginUrl = Config.SITE_LOGIN_URL;

// header
let header = {
  "Content-type": "application/json; charset=UTF-8"
};


// need to use double quote
let body = JSON.stringify({
  "form_type": "customer_login",
  "customer[email]": "user",
  "customer[password]": "pass"
});


// header, body, post
const sourceObj = {
  uri: loginUrl,
  headers: header,
  body: body,
  method:'POST'
};

let webviewInstance = <WebView
    source={sourceObj}
    style={{ marginTop: 20 }}
    onLoadProgress={e => console.log(e.nativeEvent.progress)}
/>;

// get empty instance
let myWebview = MyWebview.getInstance();
// inject the instance
myWebview.setWebview(webviewInstance);
// get webview instance
let origWebviewInstance = myWebview.getWebview();


// NOTE: not able to change url
origWebviewInstance.source = {uri: 'https://google.com'};


type Props = {};
export default class App extends Component<Props> {
  render() {

    return (
        origWebviewInstance
    );
  }
}

0 个答案:

没有答案