riot / route

Simple isomorphic router
MIT License
212 stars 40 forks source link

Router fails entirely when not in index of a folder #137

Closed AshenPheonix closed 4 years ago

AshenPheonix commented 4 years ago

Demonstration When not in index of folder, router fails entirely or copies address repeatedly.

GianlucaGuarini commented 4 years ago

@AshenPheonix please update your component using the following code:

<blog>
  <Router base={state.base}>
    <select onchange={change_demo}>
      <option value="">Home</option>
      <option value="1">Opt 1</option>
      <option value="2">Opt 2</option>
    </select>
    <Route path="#">
      Home
    </Route>
    <Route path="#/:id">
      Option {route.params[0]}
    </Route>
  </Router>

  <script>
    import {Router,Route,router,setBase} from '@riotjs/route'
    const loc = window.location

    export default{
      components:{
        Router,
        Route
      },
      state:{
        base: `${loc.protocol}//${loc.host}${loc.pathname}`
      },
      onBeforeUpdate(props,state){

      },
      onBeforeMount(props,state){
      },
      onMounted(){
        // set the initial hash route
        if (!window.location.hash) router.push('#')
      },
      change_demo(e){
        console.log(e)
        router.push(`#/${e.target.value}`)
      }
    }
  </script>
</blog>