从缩短URL的React-Native图像加载不起作用

时间:2018-12-15 11:50:56

标签: image api react-native url-shortener

我正在渲染<Image>组件,该组件具有如下所示的图像的远程服务器URL,

<Image source={{ uri: 'bit.ly/2RkIi9w' }} style={{ width:100 , height:100}} />

但是它不能正常工作。缩短的原始url使用协议https://

我已经尝试通过给它提供简单的url,并且效果很好。但网址不能缩短。

<Image source={{ uri: 'https://d1w7fb2mkkr3kw.cloudfront.net/assets/images/book/lrg/9780/1363/9780136350385.jpg' }} style={{ width:100 , height:100}} />

为什么会这样? URL重定向在react-native中出错吗?如果有解决方案,请告诉我。

3 个答案:

答案 0 :(得分:2)

很简单,您只需在链接之前添加协议,就像

<Image source={{ uri: 'https://'+your_link }} style={{ width:100 , height:100}} />

将解决您的问题。

答案 1 :(得分:1)

您可以使用它来扩展缩短的URL。

https://www.npmjs.com/package/react-native-google-shortener

// first argument should shortened url
expand('https://goo.gl/').then(response => {
  console.log(response.id);
  console.log(response.longUrl);
});

答案 2 :(得分:1)

只需在链接之前添加协议https

<Image source={{ uri: 'https://bit.ly/<path>' }} style={{ width:100 , height:100}} />