How to redirect via a simple method?



  • I tried to do an account synchronization plugin, but the middle of the need to force the routing of the jump.(I want to use filter:router.page,but i don't know how to use it.)
    I tried filter:middleware.render, like below: (But it is not a friendly way.I want to handle redirect via a simple method.Cloud you help me ? Thanks you.)

    if (data.req.session.hasOwnProperty('connect') && !(Array.isArray(data.templateData.url.match(/register/))) && (!data.req.hasOwnProperty('user') || !data.req.user.hasOwnProperty('uid') || data.req.user.uid === 0)) {
                if (data.req.headers['x-requested-with'] && data.req.headers['x-requested-with'].toLowerCase() === 'xmlhttprequest') {
                    // is ajax
                    callback(new Error('Emmm. Use F5 to redirect truly page'))
                } else {
                    // is common request
                    data.res.redirect('/register')
                    callback(null, data)
                }
            } else if (data.req.session.hasOwnProperty('cuser') && !(Array.isArray(data.templateData.url.match(/connect\/login/)))) {
                if (data.req.headers['x-requested-with'] && data.req.headers['x-requested-with'].toLowerCase() === 'xmlhttprequest') {
                    // is ajax
                    callback(new Error('Emmm. Use F5 to redirect truly page'))
                } else {
                    // common request
                    data.res.redirect('/connect/login')
                    callback(null, data)
                }
            } else {
    .........
    

  • Admin

    Can you explain the "routing of the jump" in more detail?



  • @julian for example: I put connect save to session.And when the session exists, when I load any page I want to redirect to the page I specified.(e.g I view /recent,redirecting to /register)


  • Admin

    Replied via your other topic.



  • @julian Thank you very much


 

Suggested Topics

| |