【问题标题】:Unable to navigate to child router route in aurelia无法导航到 aurelia 中的子路由器路由
【发布时间】:2016-12-07 07:06:04
【问题描述】:

我有两个子应用程序“Solace”和“UM”,我打算为其拥有自己的路由器。我的主要应用是“mcc-gui”。

目前,我正在尝试将主路由器中定义的路由“mcc-gui/um”导航到子路由器(即 UM 的路由器),但我无法执行此操作。

我确实收到了一个错误“Unexpected token

但是,当我使用路由 mcc-gui/solace/devices 直接从主路由器对另一个子应用“Solace”执行操作时,将呈现所需的视图。

这是我用于主路由器的 app.js:

export class App {
    configureRouter(config,router){
        config.title = 'MCC GUI';
        config.options.pushState=true;
        config.map(
          [
            {route:  '', name:'default',redirect: 'mcc-gui/solace/devices'},
{route:  'mcc-gui/solace/devices', name:'solace_devices',moduleId: './sections/middleware/solace/devices/devices', nav: true, title: 'Devices',settings:{icon: 'fa fa-server'}},
            {route:  'mcc-gui/um', name:'um', title: 'UM', moduleId: './sections/middleware/um/main', nav: true, settings:{icon: 'glyphicon-road'}},

        ]);
        this.router=router;
    }
}

这是我的子路由器 main.js(在 mcc-gui\src\sections\middleware\um 内)

export class Main {

  configureRouter(config,router){
    config.title = 'MCC For UltraMessaging!';
    config.options.pushState=true;

     config.map([
                  {route:  '', name:'default', redirect: 'transports'},

                  {route:  'transports', name:'transports', moduleId: './transports/transports', nav: true, title: 'Transports',settings:{icon: 'glyphicon-road'}}


                 ]);
    this.router=router;
  }
}

这是我的 main.html

 <template>
      <require from='./nav-bar'></require>

      <!--<nav-bar router.bind="router"></nav-bar>-->

      <div class="page-host">
        <router-view></router-view>
      </div>
    </template>

这是我的项目布局: C:\dev\messagingcommandcenter\mcc-gui\htdocs\mcc-gui\src>树

        ├───sections  
        │   └─── middleware  
        │        ├───solace  
        │       │   ├───connections  
        │       │   └───devices  
        │       └───um  
        │           ├───receivers  
        │           ├───sources  
        │           └───transports  
        |           |      |  
        |           |      |--transports.html  
        |           |         transports.js  
        |           |       
        |           |---main.html  
        |               main.js  
        |               nav-bar.html  
        |               nav-bar.js  
        |    
        |--.eslintrc  
            app.html  
            app.js       
            main.js  
            nav-bar.html  
            nav-bar.js  

【问题讨论】:

    标签: javascript aurelia


    【解决方案1】:

    在我看来,在您在 App 类中配置的路由器中 - 您正在重定向到不存在的路由。

    【讨论】:

    • 抱歉,刚刚编辑了问题。主路由器中有很多路由,因此我们决定将其分解为子路由器/应用程序。在发布问题时,我们稍微清理了路由器代码以使其更易于阅读。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    相关资源
    最近更新 更多