<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="app">
        <ul>
            <li><a href="#/">Home</a></li>
            <li><a href="#/about">About</a></li>
        </ul>
        <div id="view"></div>
    </div>

    <script>
        let Home = {
            template:'<h2>this is home</h2>'
        }

        let About = {
            template: '<h2>this is about</h2>'
        }

        let Router = function (el) {
            let view = document.getElementById(el);
            let routes = [];
            let load = function (route) {
                route && (view.innerHTML = route.template)
            }
            
            let redirect = function () {
                let url = window.location.hash.slice(1) || '/'
                for(let route of routes){
                    url === route.url && load(route)
                }
            }
            
            this.push = function (route) {
                routes.push(route);
            }
            window.addEventListener('load',redirect,false)
            window.addEventListener('hashchange',redirect,false)
        }

        let router = new Router('view');
        router.push({
            url:'/',
            template:Home
        });
        router.push({
            url:'/about',
            template:About
        });


    </script>
</body>
</html>