fix: improve type safety and error handling in arkts-development
- Replace Record<string, Object> with specific interface types for router params - Add error handling catch block to list-page-template.ets - Add clarification note for router.back() with params - Improve type safety following ArkTS best practices
This commit is contained in:
@@ -65,24 +65,31 @@ router.back({
|
||||
url: 'pages/HomePage'
|
||||
});
|
||||
|
||||
// Back with result
|
||||
router.back({
|
||||
url: 'pages/HomePage',
|
||||
params: { result: 'success' }
|
||||
});
|
||||
```
|
||||
|
||||
### Get Parameters
|
||||
|
||||
```typescript
|
||||
// In target page
|
||||
aboutToAppear(): void {
|
||||
const params = router.getParams() as Record<string, Object>;
|
||||
if (params) {
|
||||
const id = params['id'] as number;
|
||||
const title = params['title'] as string;
|
||||
}
|
||||
}
|
||||
// Back with result
|
||||
router.back({
|
||||
url: 'pages/HomePage',
|
||||
params: { result: 'success' }
|
||||
});
|
||||
// Note: Previous page receives params via router.getParams()
|
||||
```
|
||||
|
||||
### Get Parameters
|
||||
|
||||
```typescript
|
||||
// Define expected params interface
|
||||
interface PageParams {
|
||||
id: number;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
// In target page
|
||||
aboutToAppear(): void {
|
||||
const params = router.getParams() as PageParams;
|
||||
if (params) {
|
||||
const id = params.id;
|
||||
const title = params.title;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Get Router State
|
||||
|
||||
Reference in New Issue
Block a user