Your shiny new app is complete and ready to be shown to the world, but you do not want to use the default .github.io domain. You want a fully customized domain name to give customers or users a seamless experience. What do you do? In this guide, you'll learn about the various types of domains supported by GitHub pages and how to configure a custom domain on Github pages.
If you're using a module bundler like webpack or parcel, ensure you push your production build to your GitHub repository. This also applies to frameworks or libraries like React, Angular, or Vue. Bear in mind that GitHub pages do not fully support single-page applications, especially when you're using an HTML5 history API-based routing solution like react-router-dom
. To get around this, use the HashRouter
rather than BrowserRouter
, as shown below.
1import React from 'react';
2import { HashRouter, Route, Link } from 'react-router-dom'
3
4function Homepage(){
5render(){
6 <div>
7 <p>Homepage</p>
8 </div>
9}
10
11function App(){
12 render(){
13 <HashRouter basename='/'>
14 <Route exact path='/homepage' component={Homepage}/>
15 </HashRouter>
16);
17}
A link to the homepage route would return a link as shown below.
1<a href='#/homepage'>....
Follow my guide Deploying React on Github Pages to help you through the deployment process of a React app on GitHub pages.
GitHub Pages supports two domain types, subdomains and apex domains. See examples of each below.
1// Examples
2Subdomain type | Example
3-------------------|-----------------
4www subdomain | www.pluralsight.com
5Custom subdomain | app.pluralsight.com
6Apex domain | pluralsight.com
7------------------------------------------
For a subdomain such as app.pluralsight.com, add a CNAME record to your domain service provider.
Follow the following steps to configure a subdomain:
<USER_NAME>.github.io
where <USER_NAME>
is your GitHub username.You can optionally choose to enforce HTTPS in your settings on GitHub.
Note that DNS changes can take up to 24 hours to reflect.
For apex domains, configure an ALIAS or ANAME/A record. To reiterate, an example apex domain would be pluralsight.com.
Follow the following steps to configure an apex domain:
Visit the dashboard provided by your domain provider and add an ALIAS or ANAME/A record pointing to your apex domain to the IP addresses of GitHub pages, as shown:
i. 185.199.108.153
ii. 185.199.109.153
iii. 185.199.110.153
iv. 185.199.111.153