/如果角度2中不存在路径,我试图重定向404 其他路径
我尝试研究有角度1的一些方法但不是角度2.
这是我的代码:
@RouteConfig([
{
path: '/news',
name: 'HackerList',
component: HackerListComponent,
useAsDefault: true
},
{
path: '/news/page/:page',
name: 'TopStoriesPage',
component: HackerListComponent
},
{
path: '/comments/:id',
name: 'CommentPage',
component: HackerCommentComponent
}
])
Run Code Online (Sandbox Code Playgroud)
所以例如,如果我重定向到/news/page/它然后它工作,它返回一个空页面你如何处理这种情况发生?
Future<List<Future<News>>> getNewsList(skipItems) async {
final response = await http.get(
'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty');
if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON
var responseNewsList = json.decode(response.body);
newsList = responseNewsList as List;
var resNewsList = (responseNewsList as List)
.skip(skipItems)
.take(20)
.map((id) => this.fetchNewsDetails(id))
.toList();
return resNewsList;
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load post');
}
}
Future<News> fetchNewsDetails(id) async {
final response = await http.get(
'https://hacker-news.firebaseio.com/v0/item/$id.json?print=pretty'); …Run Code Online (Sandbox Code Playgroud)