[web] Assert route names start with / if using PathUrlStrategy (#127986)
To avoid confusion and unpredictable errors (e.g. https://github.com/flutter/flutter/issues/127462), I'm adding this assert to disallow this pattern. Fixes https://github.com/flutter/flutter/issues/127462
This commit is contained in:
@@ -63,9 +63,15 @@ class PathUrlStrategy extends ui_web.HashUrlStrategy {
|
||||
|
||||
@override
|
||||
String prepareExternalUrl(String internalUrl) {
|
||||
if (internalUrl.isNotEmpty && !internalUrl.startsWith('/')) {
|
||||
internalUrl = '/$internalUrl';
|
||||
if (internalUrl.isEmpty) {
|
||||
internalUrl = '/';
|
||||
}
|
||||
assert(
|
||||
internalUrl.startsWith('/'),
|
||||
"When using PathUrlStrategy, all route names must start with '/' because "
|
||||
"the browser's pathname always starts with '/'. "
|
||||
"Found route name: '$internalUrl'",
|
||||
);
|
||||
return '$_basePath$internalUrl';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user