{"size": 1533, "ext": "js", "max_stars_repo_path": "src/components/router/router-view.js", "max_stars_repo_name": "bxb-space/bxb-site-builder", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/router/router-view.js", "max_issues_repo_name": "bxb-space/bxb-site-builder", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/router/router-view.js", "max_forks_repo_name": "bxb-space/bxb-site-builder", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.55, "max_line_length": 99, "alphanum_fraction": 0.558382257}
{{- define "router-view" -}}
Vue.component('router-view', {
  props: {},
  components: {},
  created(){
    this.sanitizeHash()
    window.addEventListener('hashchange', this.sanitizeHash)
  },
  // mounted(){},
  // updated(){},
  // activated(){},
  // beforeDestroy(){},
  watch: {},
  computed: {},
  methods: {
    sanitizeHash: function(){
      if (window.location.href.split('/#/').length === 2){
        // console.log("route is correctly set")
        this.setClientSideSeparator(this.clientSideHash())
        this.findRoute(this.clientSideHash())
      } else {
        console.log("route has been normalized")
        this.setClientSideSeparator()
        this.currentPage = 'landing-page'
      }
    },
    setClientSideSeparator: function(hash){
      if (!hash) hash = "";
      history.pushState( null, null, window.location.pathname.replace(/(\/)+$/, "") + "/#/" + hash)
    },
    clientSideHash: function(){
      return window.location.href.split('/#/')[1] || '';
    },
    findRoute: function(hash){
      hash = "/" + hash
      // console.log(`looking for route ${hash} ..`)
      if (App.router.routes[hash]){
        // console.log("route found")
        this.currentPage = App.router.routes[hash].component
      } else {
        // console.log("route not found")
        this.handle404()
      }
    },
    handle404: function(){
      console.log("404 ERROR")
    }
  },
  data() {
    return {
      currentPage: 'landing-page'
    }
  },
  template: `
<div :is="currentPage">
</div>
`
})
{{- end -}}
