Navigate back to the homepage

How to encode a URL in react native

React Native
August 10th, 2021 · 1 min read
How to encode a URL in react native

Hello Friends 👋,

Welcome To Infinitbility! ❤️

This tutorial will help you to encode your URL in react native, we know react-native javascript codebase and javascript provide two methods to encode URL encodeURI() and encodeURIComponent().

Depending on what you need to do, there are 2 JavaScript functions that will help you.

The first is encodeURI(), and the second is encodeURIComponent().

Note: you might read about escape(), but that is deprecated and should not be used.

Those 2 methods differ in which characters they do encode.

In details, encodeURI() does not encode [email protected]#$&*()=:/,;?+ and encodeURIComponent() does not encode -_.!~*'(), encoding all the other characters. Why do they differ? Because they are meant for different uses:

  • encodeURI() is meant to encode a full URL
  • encodeURIComponent() is meant to encode a single URL parameter value
  • Final Result: React login form

If you were to call encodeURIComponent() on a full URL since it does encode /, the URL path separators would be encoded as well (among other things):

1import React from 'react';
2import base64 from 'react-native-base64'
3import { View, Text } from 'react-native';
5class ReactNativeComponents extends React.Component {
6 constructor(props){
7 super(props);
8 }
10 componentDidMount() {
11 encodeURI(" encodeURI/")
12 // ""
14 encodeURIComponent(" encodeURI/")
15 // ""
16 }
18 render() {
19 return (
20 <View>
21 <Text>React Components</Text>
22 </View>
23 );
24 }
27export default ReactNativeComponents;

Thanks for Reading…

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide



More articles from Infinitbility

How to encode and decode base64 in react native

How to encode and decode base64 in react native

React Native base64 Example

August 10th, 2021 · 1 min read
How to create and use function in react native

How to create and use function in react native

React Native functions Example

August 9th, 2021 · 1 min read
© 2020–2022 Infinitbility
Link to $ to $ to $ to $ to $ to $mailto:[email protected]