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

如何在跳转过程中中止中跳转并跳到另一个页面? #5

Closed
Neugls opened this issue Dec 5, 2017 · 11 comments
Closed

Comments

@Neugls
Copy link

Neugls commented Dec 5, 2017

是这样的情况:

const router = Restate({routes: {
   'app': {
           url: '',
           view: Application
    },
    'app.introduce':{
           url: '',
            view: Introduce
    },
   'app.view': {
           view: View
    }
})

默认是会跳转到 app.introduce, 但如果因为某些条件的需要比如恢复上次的状态, 这个时候就不需要先转到app.introduce, 有没有方法可以直接启动就跳转到app.view.

如果在初始化后直接调用: router.go("app.view") 会出现app里的共有模板出现双份复制的情况

@Neugls
Copy link
Author

Neugls commented Dec 5, 2017

现在的到一个不知道是不是的解决方案:

在 view 的enter 勾子里这样写:

enter: function(option, resolve){
         if( 条件 ){
            this.$state.go("app.view")
         }
        resolve();
}

或者是通过setTimeout来解决, 但setTimeout 会出现闪的问题

@leeluolee
Copy link
Member

需求是 app.view 跳出前要加判断么?

@Neugls
Copy link
Author

Neugls commented Dec 6, 2017

需求是要在

app.introduce 

显示出来前进行判断跳转

@fengzilong
Copy link
Member

fengzilong commented Dec 15, 2017

Introduce.js

{
    canEnter: function ( e ) {
        if ( ... ) {
            e.stop();
            this.$state.go( 'app.view' );
        }
    }
}

@Neugls 试试这个

@Neugls
Copy link
Author

Neugls commented Dec 20, 2017

@fengzilong
canEnter 也是一个勾子函数吗?我在view里加了这个方法, 加断点并不会被正确调用, 文档里好像也没有这个函数的说明

@fengzilong
Copy link
Member

fengzilong commented Dec 20, 2017

我看代码里面是有这个钩子函数的呀

regular-state/restate.js

Lines 162 to 164 in db72456

var canEnter = this.component && this.component.canEnter;
if( canEnter ) return this.component.canEnter(option);

你把断点打在上面这个位置试试

@Neugls
Copy link
Author

Neugls commented Dec 20, 2017

@fengzilong OK, 我刚看了state-man的文档, 有这样的一段代码

stateman.state('app.user',{
  'canEnter': function(){
    return !!isUser;
  }
})

和你说的, 我都试试, 谢谢!

@Neugls
Copy link
Author

Neugls commented Dec 20, 2017

@fengzilong 可能是版本的问题, 我现在用的是 regular-state@^0.6.0-beta.8

没有restate.js

@fengzilong
Copy link
Member

@Neugls 是版本问题,我直接去看master的代码了...

新版本好像是这么用的

manager.state('app.blog', {
    url: '/blog/:id'
    view: Blog,
    canEnter( e ) {
        // ...
    }
})

你试下可以么

@Neugls
Copy link
Author

Neugls commented Dec 20, 2017

@fengzilong
image

像上图一样, 新版本能够正常调用,也能正常跳转!谢谢!

@fengzilong
Copy link
Member

不客气,那这个issue我关掉了~~

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

3 participants