这样一个导航
通过koarouter跳转的 但是这么跳转时候给他一个样式或者类名
router.get('/contantus', async ctx => {
console.log(ctx.response)
await ctx.render('contantus', {title: "联系我们"})
})
router.get('/products', async ctx => {
await ctx.render('products', {title: "产品列表"})
})
这里是HMTL
<ul class="nav-list">
<li>首页</li>
<li class={{active}}><a href="/products">产品</a> </li>
<li>解决方案</li>
<li><a href="/contantus">联系我们</a> </li>
</ul>
用的是koa-nunjucks-2模板引擎 本来我是传过来一个active但是所有的都变了
有什么方法可以加入样式
楼主可以换个思路来解决,可以根据当前的
url
地址来匹配,如果当前url
是products
,那就在产品的li
上添加active
。不需要koa-router
做任何操作的。