Created
May 3, 2016 00:25
-
-
Save pbojinov/e51d1f1c55bd8b7fc596725b62e1aed8 to your computer and use it in GitHub Desktop.
React Native App with Deep Link Support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { View, Text, Linking } from 'react-native'; | |
import urlParse from 'url-parse'; | |
class App extends Component { | |
componentDidMount() { | |
// Handling Deep Linking | |
const deepLinkUrl = Linking.getInitialURL().then((url) => { | |
console.log(`Deep Link URL: ${url}`); | |
if (url) { | |
const parsedUrl = urlParse(url, true); | |
const {query: {userId}} = parsedUrl; | |
// if user id query param exists, lets load that user's profile | |
if (userId) { | |
this._loadUserProfile(userId); | |
} | |
} | |
}).catch(err => console.error('An error occurred', err)); | |
} | |
_loadUserProfile() { | |
// ..do something | |
} | |
render() { | |
return ( | |
<View> | |
<Text>Hello World</Text> | |
</View> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment