在 Kanary 中,所有路由都定义在 app.routes 数组中,当服务器收到请求时,路由模块 会查询请求匹配的路由规则并根据路由的描述调度 控制器 。
在 Kanary 中定义路由有几种方法:
下面我们依次介绍:
exports.routes = [
'get / => home#index'
];
import { get } from 'kanary/router';
class Home {
@get('/hi')
async index(){
return 'hello world';
}
}
export default Home;
module.exports = app => {
app.router.get('/').to('home', 'index');
}