{"size": 964, "ext": "js", "max_stars_repo_path": "webpack/src/router.js", "max_stars_repo_name": "vtex-developers/vtex-email-framework", "max_stars_repo_stars_event_min_datetime": "2021-01-20T15:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-25T14:12:22.000Z", "max_issues_repo_path": "webpack/src/router.js", "max_issues_repo_name": "vtex-developers/vtex-email-framework", "max_issues_repo_issues_event_min_datetime": "2022-02-14T01:00:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T11:17:45.000Z", "max_forks_repo_path": "webpack/src/router.js", "max_forks_repo_name": "vtex-developers/vtex-email-framework", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 31.0967741935, "max_line_length": 71, "alphanum_fraction": 0.4958506224}
import dashboard from './view'

const router = ({ search, pathname }) => {
    const pathName = search ? `/${search.split('?')[1]}` : pathname
    fetch(`http://localhost:5050${pathName}`)
        .then(res => res.text())
        .then(data => {
            document.body.innerHTML = data
            const title = document.body.querySelector('title')
            if(title){
                document.title = title.text
            }
            if (pathName == "/") {
                dashboard()
            }
            
            const partials = [...document.querySelectorAll('.partial')]
            if(partials.length >= 1){
                partials.forEach(partial => {
                    const childrens = partial.innerHTML
                    partial.insertAdjacentHTML('beforebegin',childrens)
                    partial.remove()
                })
            }

        })
}

window.onpopstate = () => router(window.location)

export default router