pbojinov
5/3/2016 - 12:25 AM

React Native App with Deep Link Support

React Native App with Deep Link Support

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>
        );
    }
}