@@ -36,8 +36,25 @@ Future<shelf.Response> documentationHandler(shelf.Request request) async {
3636 if (docFilePath.version == null ) {
3737 return redirectResponse (pkgDocUrl (docFilePath.package, isLatest: true ));
3838 }
39- if (docFilePath.path == null ) {
40- return redirectResponse ('${request .requestedUri }/' );
39+ final detectedPath = docFilePath.path;
40+ if (detectedPath == null ) {
41+ return redirectResponse (
42+ pkgDocUrl (docFilePath.package, version: docFilePath.version));
43+ }
44+ // 8.3.0 dartdoc links to directories without an ending slash.
45+ // This breaks base-uri, sidebar does not load, links do not work.
46+ // Redirecting to the proper directory ending with slash.
47+ if (detectedPath.split ('/' ).last == 'index.html' &&
48+ ! request.requestedUri.path.endsWith ('/' ) &&
49+ ! request.requestedUri.path.endsWith ('/index.html' )) {
50+ // removes last segment `index.html` and adds `/` at the end of the url.
51+ return redirectResponse (
52+ pkgDocUrl (
53+ docFilePath.package,
54+ version: docFilePath.version,
55+ relativePath: detectedPath,
56+ ),
57+ );
4158 }
4259 final String requestMethod = request.method.toUpperCase ();
4360
@@ -59,10 +76,10 @@ Future<shelf.Response> documentationHandler(shelf.Request request) async {
5976 return redirectResponse (pkgDocUrl (
6077 package,
6178 version: resolved.urlSegment,
62- relativePath: docFilePath.path ,
79+ relativePath: detectedPath ,
6380 ));
6481 } else {
65- return await handleDartDoc (request, package, resolved, docFilePath.path ! );
82+ return await handleDartDoc (request, package, resolved, detectedPath );
6683 }
6784}
6885
0 commit comments