codecamp

router.redirect

router.redirect(redirectMap)

为路由器定义全局的重定向规则。全局的重定向会在匹配当前路径之前执行。如果发现需要进行重定向,原本访问的路径会被直接忽略而且不会在浏览器历史中留下记录。

参数

  • redirectMap: Object

    重定向映射对象的格式应该为 { fromPath: toPath, ... } 。路径中可以包含动态片段。

Example

router.redirect({

  // 重定向 /a 到 /b
  '/a': '/b',

  // 重定向可以包含动态片段
  // 而且重定向片段必须匹配
  '/user/:userId': '/profile/:userId',

  // 重定向任意未匹配路径到 /home
  '*': '/home'
})
router.replace
router.alias
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }