X Tutup
Skip to content

Commit 9cc1cd2

Browse files
committed
feat(url_resolver): Allow a developer to customize their package prefix
Allow a developer to specify a package prefix where the 'package:' dart urls will be resolved. By default this will be '/packages' keeping the current behavior, but allows for flexibility of different environments where a developer may not control their directory structure. Closes #3794
1 parent 894af28 commit 9cc1cd2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

modules/angular2/src/services/url_resolver.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import 'package:angular2/di.dart' show Injectable;
44

55
@Injectable()
66
class UrlResolver {
7+
/// This will be the location where 'package:' Urls will resolve. Default is
8+
/// '/packages'
9+
final String packagePrefix;
10+
11+
const UrlResolver() : packagePrefix = '/packages';
12+
13+
/// Creates a UrlResolver that will resolve 'package:' Urls to a different
14+
/// prefixed location.
15+
const UrlResolver.withUrlPrefix(this.packagePrefix);
16+
717
/**
818
* Resolves the `url` given the `baseUrl`:
919
* - when the `url` is null, the `baseUrl` is returned,
@@ -20,7 +30,7 @@ class UrlResolver {
2030
Uri uri = Uri.parse(url);
2131

2232
if (uri.scheme == 'package') {
23-
return '/packages/${uri.path}';
33+
return '$packagePrefix/${uri.path}';
2434
}
2535

2636
if (uri.isAbsolute) return uri.toString();

0 commit comments

Comments
 (0)
X Tutup