ember-simple-auth: Error: Assertion Failed: The route index was not found
ember-simple-auth: Error: Assertion Failed: The route index was not found
我正在使用 ember-simple-auth 构建应用程序。
所以它看起来非常像图书馆所做的事情。
事情是这样的:
- 用户尝试访问 /dashboard 但被重定向到 /
- 路由 / 包含登录表单
- 用户使用有效凭据登录
- 服务器响应:/token 200 0.252 ms - 52
- 但显示错误消息:错误:断言失败:找不到路由索引
- 用户导航至 /dashboard,现在可以查看内容、在保护区内导航并成功注销。
我的问题是,如何将 /dashboard 定义为路由而不是索引?这样在成功登录后您将被重定向到 /dashboard
您可以在配置中配置 Ember Simple Auth 的 routeAfterAuthentication
,例如
ENV['ember-simple-auth'] = {
routeAfterAuthentication: 'dashboard'
}
4年后...
在 Ember Simple Auth 部分,您可以添加 routeAfterAuthentication
并收工,因为 ESA 默认为 index
。
如果我们深入挖掘,就为什么 ESA 曾经并且仍然默认使用 Index
路由而言,是 Ember 总是为您生成 2 条路由:
- 一个
""
用于 ApplicationRoute
- 和
"/"
用于 IndexRoute,
您可以免费获得这 2 条路线。
我找到了 3.20 version doc's wording is verbose, so I'm pasting from 1.10 文档,但思路还是一样
从这个角度来看,ESA 使用 IndexRoute
作为默认值是一个安全的选择。
我正在使用 ember-simple-auth 构建应用程序。
所以它看起来非常像图书馆所做的事情。
事情是这样的:
- 用户尝试访问 /dashboard 但被重定向到 /
- 路由 / 包含登录表单
- 用户使用有效凭据登录
- 服务器响应:/token 200 0.252 ms - 52
- 但显示错误消息:错误:断言失败:找不到路由索引
- 用户导航至 /dashboard,现在可以查看内容、在保护区内导航并成功注销。
我的问题是,如何将 /dashboard 定义为路由而不是索引?这样在成功登录后您将被重定向到 /dashboard
您可以在配置中配置 Ember Simple Auth 的 routeAfterAuthentication
,例如
ENV['ember-simple-auth'] = {
routeAfterAuthentication: 'dashboard'
}
4年后...
在 Ember Simple Auth 部分,您可以添加 routeAfterAuthentication
并收工,因为 ESA 默认为 index
。
如果我们深入挖掘,就为什么 ESA 曾经并且仍然默认使用 Index
路由而言,是 Ember 总是为您生成 2 条路由:
- 一个
""
用于 ApplicationRoute - 和
"/"
用于 IndexRoute,
您可以免费获得这 2 条路线。
从这个角度来看,ESA 使用 IndexRoute
作为默认值是一个安全的选择。