Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带aviator的散列路由_Javascript_Routing - Fatal编程技术网

Javascript 带aviator的散列路由

Javascript 带aviator的散列路由,javascript,routing,Javascript,Routing,我很好奇为什么中的代码不起作用 我正在尝试设置哈希路由 当我单击该按钮时,哈希更改成功,但函数handleOutlineRoute从未被调用 以下是我的javascript: class Application { init() { this.configureRouter() this.setupRoutes() this.dispatch() } configureRouter() { Aviator.pushStateEnabled = fa

我很好奇为什么中的代码不起作用

我正在尝试设置哈希路由

当我单击该按钮时,哈希更改成功,但函数
handleOutlineRoute
从未被调用

以下是我的javascript:

class Application {

  init() {
    this.configureRouter()
    this.setupRoutes()
    this.dispatch()
  }

  configureRouter() {
    Aviator.pushStateEnabled = false
  }

  dispatch() {
    Aviator.dispatch()
  }

  setupRoutes() {
    Aviator.setRoutes({
        '/': {
        target: this,
        '/': 'handleWelcomeRoute',
        '/outline': 'handleOutlineRoute'
      }
    })
  }

  handleWelcomeRoute() {
    alert('welcome')
  }

  handleOutlineRoute() {
    alert('outline')
  }

}

(function() {
  const app = new Application()
  app.init()
  $('a.nav').attr('href', `#${Aviator.hrefFor('/outline')}`)
})()
和HTML:

<a class="nav"> Click Me </a>
点击我

当从路由配置中增加嵌套级别时,问题得到解决

Aviator.setRoutes({
    target: this,
    '/': 'handleWelcomeRoute',
    '/outline': 'handleOutlineRoute'
})
库将
/
视为终端端点