JavaScript框架路由器中的动态分层路由器

时间:2015-11-17 19:47:44

标签: javascript javascript-framework aurelia aurelia-router

我们已经决定使用Aurelia作为JS框架,但是在路由方面遇到了障碍。我们有分层导航,Aurelia路由器不支持(https://github.com/aurelia/router/issues/90)。

导航还取决于谁登录,主导航的每个路径可以有1,2或3个级别。以下是我们现在使用knockoutjs(我们正在转向SPA)的示例:http://jsfiddle.net/22dy9yqw/4/。导航的数据源必须是表示导航结构的嵌套JSON对象,并且UI必须保持原样(底层是下拉列表)。以下是我们结构的一个示例:

[
{
    "name": "No SubNav",
    "href": "\/no-subnav",
    "id": "no-subnav"
}, 
{
    "name": "Settings",
    "href": "\/settings\/",
    "id": "settings",
    "children": [
        {
            "name": "Setting1",
            "href": "\/settings\/setting1\/",
            "id": "setting1"
        }, {
            "name": "Setting2",
            "href": "\/settings\/setting2\/",
            "id": "setting2"
        }
    ]
},
{
    "name": "Reports",
    "href": "\/reports\/",
    "id": "reports",
    "children": [
        {
            "name": "Section1",
            "href": "\/reports\/section1\/",
            "id": "section1",
            "children": [
                {
                    "name": "Section1 Report1",
                    "href": "\/reports\/section1\/report1",
                    "id": "report1-1",
                }, {
                    "name": "Section1 Report2",
                    "href": "\/reports\/section1\/report2",
                    "id": "report1-2",
                }, {
                    "name": "Section1 Report3",
                    "href": "\/reports\/section1\/report3",
                    "id": "report1-3",
                }
            ]
        }, {
            "name": "Section2",
            "href": "\/reports\/section2\/",
            "id": "section2",
            "children": [
                {
                    "name": "Section2 Report1",
                    "href": "\/reports\/section2\/report1",
                    "id": "section2-1",
                }, {
                    "name": "Section2 Report2",
                    "href": "\/reports\/section2\/report2",
                    "id": "section2-2",
                }, {
                    "name": "Section2 Report3",
                    "href": "\/reports\/section2\/report3",
                    "id": "section2-3",
                }, {
                    "name": "Section2 Report4",
                    "href": "\/reports\/section2\/report4",
                    "id": "section2-4",
                }, {
                    "name": "Section2 Report5",
                    "href": "\/reports\/section2\/report5",
                    "id": "section2-5",
                }
            ]
        }
    ]
}
]

使用Aurelia可以轻松完成这样的事情,同时仍然可以利用其他路由器功能(例如,映射)吗?有更好的解决方案吗?我是JS框架世界的新手,我有点不知所措。

0 个答案:

没有答案