利用 Angular 路由构建单页应用及后端集成
1. 路由重定向配置
在 customers_controller.rb 中, index 方法进行了路由重定向配置:
def index
# method as it was before...
respond_to do |format|
format.html {
redirect_to customers_ng_path
}
format.json {
render json: { customers: @customers }
}
end
end
通过上述代码,任何对 /customers 的访问都会被重定向到 /customers/ng ,从而渲染现有的 Angular 应用。重启 Rails 后,访问 http://localhost:5000/customers ,会被重定向到 http://localhost:5000/customers/ng ,并且可以看到现有的客户搜索功能。
2. 客户端导航实现
2.1 添加导航按钮
在搜索结果中添加一个按钮,点击该按钮可以从 /customers/ng 导航到 /customers/ng/<customer id>
超级会员免费看
订阅专栏 解锁全文
2146

被折叠的 条评论
为什么被折叠?



