Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持路由嵌套么? #13

Open
koyoyoo opened this issue Nov 16, 2017 · 9 comments
Open

支持路由嵌套么? #13

koyoyoo opened this issue Nov 16, 2017 · 9 comments

Comments

@koyoyoo
Copy link

koyoyoo commented Nov 16, 2017

比如2个层级以上的路由

@itorr
Copy link
Owner

itorr commented Nov 16, 2017

多层级是支持的,q.js 不关注回调之后的事情

@koyoyoo
Copy link
Author

koyoyoo commented Nov 16, 2017

没有看见相关的资料
默认的demo只有一个 菜单,点了就出现内容。
有没有点了菜单后 又出现一个子菜单,再点才出现内容的demo?

@itorr
Copy link
Owner

itorr commented Nov 16, 2017

那需要在回调内针对传入参数对DOM进行修改

加了一个例子
https://github.com/itorr/q.js/blob/master/demos/level2.html

@koyoyoo
Copy link
Author

koyoyoo commented Nov 16, 2017

你好,我看了你给的例子,我的意思是这样:
Q.reg('home',function(type){ document.getElementById('m').innerHTML='打开了 Home 菜单<br>'; document.getElementById('m').innerHTML+='<a href="#/home/city">加载home下面的子菜单#/city</a>'; }); Q.reg('home/city',function(){//这里注册子菜单。 console.log("打开城市内容"); }); Q.init({ index:'home'/* 首页地址 */ });

@itorr
Copy link
Owner

itorr commented Nov 16, 2017

如果 view 内容完全不同 你可以用正则表达式匹配
比如 /^home/city/

正则表达式匹配优先于普通匹配

@itorr
Copy link
Owner

itorr commented Nov 16, 2017

/ -》 / 手机端发布会少一个反斜杠

@itorr
Copy link
Owner

itorr commented Nov 16, 2017

/ 替换成 \/

@koyoyoo
Copy link
Author

koyoyoo commented Nov 17, 2017

我用正则转换了/斜线,但是注册的 home/menu 不执行,求解
Q.reg('home',function(){ document.getElementById('m').innerHTML='打开了主页<br>'; document.getElementById('m').innerHTML+='加载子菜单:<a href="#/home/menu">#/home/menu</a>'; }); Q.reg('home\/menu',function(){ console.log('打开菜单页') });

@itorr
Copy link
Owner

itorr commented Nov 17, 2017

是这样的,这里需要用正则表达式 而不是字符串形式

Q.reg(/^home\/menu/,function(){
    console.log('打开菜单页');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants