codecamp

router.alias

router.alias(aliasMap)

为路由器配置全局的别名规则。别名和重定向的区别在于,相对于重定向把 fromPath 替换为 toPath ,别名会保留 fromPath ,但是匹配时使用的是 toPath

例如,如果我们把 /a 取别名为 /a/b/c ,那么当我们访问 /a 时,浏览器地址栏中的URL会是 /a 。但是路由匹配是却像是在访问 /a/b/c

参数

  • aliasMap {Object}

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

Example

router.alias({

  // 匹配 /a 时就像是匹配 /a/b/c
  '/a': '/a/b/c',

  // 别名可以包含动态片段
  // 而且重定向片段必须匹配
  '/user/:userId': '/user/profile/:userId'
})
router.redirect
router.beforeEach
温馨提示
下载编程狮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; }