Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change webview URL in React native

I have an app that has a WebView and a bottom navigation bar.

Back, forward and reload buttons work ok since there are goForward(), goBack() and reload() method.

But I also have a home button that should load the starting url. I tried setting the new url with this.setState but it doesn't work.

this.setState({
  ...this.state,
  url: DEFAULT_URL,
})

Actually it works the first time. For example if I change the URL in the source and hot reload then it works. But if I click on any link home doesn't work anymore.

Is it possible to do this and if so what am I doing wrong?

like image 932
praxus Avatar asked Sep 05 '17 12:09

praxus


1 Answers

I solved it by appending timestamp to url because it seems setting a "new" url triggers the new render() or something.

So the function now goes like this:

this.setState({ url: `${DEFAULT_URL}?t=${Date.now()}` })
like image 154
praxus Avatar answered Jan 04 '23 04:01

praxus