Skip to content

Commit 46d6c30

Browse files
committed
init
1 parent b03fab6 commit 46d6c30

6 files changed

Lines changed: 124 additions & 4 deletions

File tree

doc/en/changeLog/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22

3-
## v1.7.0 (Latest)
3+
## v1.7.1 (Latest)
4+
5+
- Enhanced integration with [mettleRouter](/tool/mettleRouter/).
6+
7+
## v1.7.0
48

59
- Introducing the `Signals` mechanism, which automatically updates components and the UI when state changes, ensuring the most efficient operation possible.
610

doc/en/essentials/api/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ function App() {
232232
}
233233
```
234234

235+
## resetView
236+
237+
Integrate [mettleRouter](/tool/mettleRouter/) to reset the current routing view.
238+
235239
## html
236240

237241
` html`` ` is a tag function. The syntax for a tag function is to directly follow the function name with a template string. For example, you can write HTML tags directly in the template string.

doc/en/tool/mettleRouter/index.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ The first parameter is an array object, which is the routing component to be reg
2020

2121
The second parameter needs to be passed to the `resetView` API, and the page matching the corresponding path will be updated accordingly.
2222

23+
The first two parameters must be passed, and the third parameter is optional and is used to configure the selector of the root node of the routing page.
24+
2325
```js
2426
// router/index.js
2527
import { resetView } from 'mettle';
@@ -39,7 +41,8 @@ const router = initRouter(
3941
template: About,
4042
},
4143
],
42-
resetView
44+
resetView,
45+
'#router',
4346
);
4447

4548
export default router;
@@ -59,6 +62,23 @@ function App() {
5962
createApp(<App />, '#app');
6063
```
6164

65+
If you configure the third parameter, the `<Router>` component must set a parent node.
66+
67+
```jsx
68+
// main.jsx
69+
import { createApp } from 'mettle';
70+
import Router from './router/index';
71+
72+
function App() {
73+
return (
74+
<div id='router'>
75+
<Router></Router>
76+
</div>
77+
);
78+
}
79+
createApp(<App />, '#app');
80+
```
81+
6282
### linkTo()
6383

6484
If you need to jump to the corresponding page, use the `linkTo()` method, you can pass the corresponding path and parameters to be passed, or you can directly pass the path string.
@@ -90,6 +110,40 @@ function About() {
90110

91111
If you perform a route parameter operation, you need to obtain the parameter object. You can directly execute the `toParse()` method to obtain the object information.
92112

113+
```jsx
114+
console.log(toParse());
115+
```
116+
117+
### hashChange
118+
119+
When the route changes, the `hashChange` event is triggered. You can listen to this event and perform custom actions.
120+
121+
```jsx
122+
import { hashChange } from 'mettle-router';
123+
124+
hashChange(() => {
125+
if (location.hash === '#/login') {
126+
isLogin.value = true;
127+
} else {
128+
isLogin.value = false;
129+
}
130+
});
131+
```
132+
133+
Returns the function to cancel listening.
134+
135+
```jsx
136+
const removeListener = hashchange(() => {
137+
console.log('Hash变化:', location.hash);
138+
});
139+
140+
// removeListener();
141+
```
142+
93143
### routerVersion
94144

95145
You can get the version information of `mettleRouter`.
146+
147+
```
148+
149+
```

doc/zh/changeLog/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# 更新日志
22

3-
## v1.7.0 (Latest)
3+
## v1.7.1 (Latest)
4+
5+
- 增强与[mettleRouter](/zh/tool/mettleRouter/)的集成。
6+
7+
## v1.7.0
48

59
- 引入 `Signals` 机制,状态变化会自动更新组件和 UI,以实现尽可能高效的操作。
610

doc/zh/essentials/api/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ function App() {
232232
}
233233
```
234234

235+
## resetView
236+
237+
集成[mettleRouter](/zh/tool/mettleRouter/),用于重置当前路由视图。
238+
235239
## html
236240

237241
` html`` `是一个标签函数,标签函数的语法是直接在函数名后跟一个模板字符串。 例如,您可以直接在模板字符串中编写 HTML 标签。

doc/zh/tool/mettleRouter/index.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ npm install mettle-router
2020

2121
第二个参数需要传递给`resetView` API,匹配到对应路径的页面会相应更新。
2222

23+
前两个参数是必须要传的,第三个参数是可选的,用于配置路由页面根节点的选择器。
24+
2325
```js
2426
// router/index.js
2527
import { resetView } from 'mettle';
@@ -39,7 +41,8 @@ const router = initRouter(
3941
template: About,
4042
},
4143
],
42-
resetView
44+
resetView,
45+
'#router',
4346
);
4447

4548
export default router;
@@ -59,6 +62,23 @@ function App() {
5962
createApp(<App />, '#app');
6063
```
6164

65+
如果你配置了第三个参数,那么`<Router>`组件必须设置一个父节点。
66+
67+
```jsx
68+
// main.jsx
69+
import { createApp } from 'mettle';
70+
import Router from './router/index';
71+
72+
function App() {
73+
return (
74+
<div id='router'>
75+
<Router></Router>
76+
</div>
77+
);
78+
}
79+
createApp(<App />, '#app');
80+
```
81+
6282
### linkTo()
6383

6484
如果需要跳转到对应的页面,使用`linkTo()`方法,可以传递对应的路径和要传递的参数,也可以直接传递路径字符串。
@@ -90,6 +110,36 @@ function About() {
90110

91111
如果执行路由参数的操作,则要获取参数对象。 直接执行`toParse()`方法可以获取对象信息。
92112

113+
```jsx
114+
console.log(toParse());
115+
```
116+
117+
### hashChange
118+
119+
当路由发生变化时,会触发`hashChange`事件。 您可以监听该事件,执行自定义操作。
120+
121+
```jsx
122+
import { hashChange } from 'mettle-router';
123+
124+
hashChange(() => {
125+
if (location.hash === '#/login') {
126+
isLogin.value = true;
127+
} else {
128+
isLogin.value = false;
129+
}
130+
});
131+
```
132+
133+
返回取消监听的函数。
134+
135+
```jsx
136+
const removeListener = hashchange(() => {
137+
console.log('Hash变化:', location.hash);
138+
});
139+
140+
// removeListener();
141+
```
142+
93143
### routerVersion
94144

95145
可以获取 `mettleRouter` 的版本信息。

0 commit comments

Comments
 (0)