You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Define "virtual" routes that can provide content dynamically. A route is a map between the expected path, to either a string or a function. If the mapped value is a string, it is treated as markdown and parsed accordingly. If it is a function, it is expected to return markdown content.
689
676
690
677
A route function receives up to three parameters:
678
+
691
679
1.`route` - the path of the route that was requested (e.g. `/bar/baz`)
692
680
2.`matched` - the [`RegExpMatchArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) that was matched by the route (e.g. for `/bar/(.+)`, you get `['/bar/baz', 'baz']`)
693
681
3.`next` - this is a callback that you may call when your route function is async
@@ -701,23 +689,23 @@ window.$docsify = {
701
689
'/foo':'# Custom Markdown',
702
690
703
691
// RegEx match w/ synchronous function
704
-
'/bar/(.*)':function(route, matched) {
692
+
'/bar/(.*)':function(route, matched) {
705
693
return'# Custom Markdown';
706
694
},
707
695
708
696
// RegEx match w/ asynchronous function
709
-
'/baz/(.*)':function(route, matched, next) {
710
-
// Requires `fetch` polyfill for legacy browsers (https://github.github.io/fetch/)
697
+
'/baz/(.*)':function(route, matched, next) {
698
+
// Requires `fetch` polyfill for legacy browsers (https://github.github.io/fetch/)
711
699
fetch('/api/users?id=12345')
712
-
.then(function(response) {
700
+
.then(function(response) {
713
701
next('# Custom Markdown');
714
702
})
715
-
.catch(function(err) {
703
+
.catch(function(err) {
716
704
// Handle error...
717
705
});
718
-
}
719
-
}
720
-
}
706
+
},
707
+
},
708
+
};
721
709
```
722
710
723
711
Other than strings, route functions can return a falsy value (`null` \ `undefined`) to indicate that they ignore the current request:
0 commit comments