-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResolver.js
31 lines (26 loc) · 820 Bytes
/
Resolver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React, {useEffect, useState} from "react";
import * as ResolverService from "./services/resolver";
import {Link, useParams} from "react-router-dom";
function Resolver() {
const { slug } = useParams();
const [status, setStatus] = useState('Redirecting...');
// look up url
useEffect(() => {
ResolverService.resolve(slug, (originalUrl) => {
console.debug(`original url: ${originalUrl}.`)
window.location.replace(originalUrl);
}, (error) => {
setStatus('Incorrect URL.')
console.error(error);
});
}, [slug]);
return (
<div className="Resolver">
<h1>
<Link to="/">URL Shortener</Link>
</h1>
<p>{status}</p>
</div>
);
}
export default Resolver;