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.
702
689
703
690
A route function receives up to three parameters:
691
+
704
692
1.`route` - the path of the route that was requested (e.g. `/bar/baz`)
705
693
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']`)
706
694
3.`next` - this is a callback that you may call when your route function is async
@@ -714,23 +702,23 @@ window.$docsify = {
714
702
'/foo':'# Custom Markdown',
715
703
716
704
// RegEx match w/ synchronous function
717
-
'/bar/(.*)':function(route, matched) {
705
+
'/bar/(.*)':function(route, matched) {
718
706
return'# Custom Markdown';
719
707
},
720
708
721
709
// RegEx match w/ asynchronous function
722
-
'/baz/(.*)':function(route, matched, next) {
723
-
// Requires `fetch` polyfill for legacy browsers (https://github.github.io/fetch/)
710
+
'/baz/(.*)':function(route, matched, next) {
711
+
// Requires `fetch` polyfill for legacy browsers (https://github.github.io/fetch/)
724
712
fetch('/api/users?id=12345')
725
-
.then(function(response) {
713
+
.then(function(response) {
726
714
next('# Custom Markdown');
727
715
})
728
-
.catch(function(err) {
716
+
.catch(function(err) {
729
717
// Handle error...
730
718
});
731
-
}
732
-
}
733
-
}
719
+
},
720
+
},
721
+
};
734
722
```
735
723
736
724
Other than strings, route functions can return a falsy value (`null` \ `undefined`) to indicate that they ignore the current request:
0 commit comments