From 353da42cce517c5e20ad38ff39c13f940301450a Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Thu, 24 May 2018 09:54:43 +0100 Subject: [PATCH] Clean up use of relative URLs. Fixes #844 and #845 (#878) * Handle links to empty-string href, resolved against base href Needed to change the URLs used in E2E tests to be able to cover this (i.e., removed the /RouterTest prefixes so the default relative URL became an empty string) * Change links in StandaloneApp sample to be relative * Standardize on base URIs having trailing slash everywhere Hence also change terminology from "base URI prefix" to simply "base URI" * Handle link highlighting when visiting base-href-but-without-trailing-slash * Removing leading slashes from base-relative URLs in templates --- samples/StandaloneApp/Pages/FetchData.cshtml | 6 +- samples/StandaloneApp/Shared/NavMenu.cshtml | 8 +-- .../src/Services/UriHelper.ts | 22 +++--- .../Services/BrowserServiceProvider.cs | 4 +- .../Services/BrowserUriHelper.cs | 69 ++++++++++--------- .../Pages/FetchData.cshtml | 2 +- .../Shared/NavMenu.cshtml | 8 +-- .../Pages/FetchData.cshtml | 2 +- .../Shared/NavMenu.cshtml | 8 +-- .../Routing/NavLink.cs | 50 ++++++++++---- .../Routing/Router.cs | 10 +-- .../Services/IUriHelper.cs | 18 ++--- .../BrowserUriHelperTest.cs | 40 ++++++----- .../Tests/RoutingTest.cs | 61 +++++++++++----- .../BasicTestApp/RouterTest/Default.cshtml | 3 +- .../BasicTestApp/RouterTest/Links.cshtml | 20 +++--- .../BasicTestApp/RouterTest/Other.cshtml | 3 +- .../BasicTestApp/RouterTest/TestRouter.cshtml | 1 - .../RouterTest/WithParameters.cshtml | 4 +- 19 files changed, 193 insertions(+), 146 deletions(-) diff --git a/samples/StandaloneApp/Pages/FetchData.cshtml b/samples/StandaloneApp/Pages/FetchData.cshtml index e32bafa791..06ae482c55 100644 --- a/samples/StandaloneApp/Pages/FetchData.cshtml +++ b/samples/StandaloneApp/Pages/FetchData.cshtml @@ -34,10 +34,10 @@ else

- + ◀ Previous - + Next ▶

@@ -57,7 +57,7 @@ else protected override async Task OnParametersSetAsync() { forecasts = await Http.GetJsonAsync( - $"/sample-data/weather.json?date={StartDate.ToString("yyyy-MM-dd")}"); + $"sample-data/weather.json?date={StartDate.ToString("yyyy-MM-dd")}"); // Because StandaloneApp doesn't really have a server endpoint to get dynamic data from, // fake the DateFormatted values here. This would not apply in a real app. diff --git a/samples/StandaloneApp/Shared/NavMenu.cshtml b/samples/StandaloneApp/Shared/NavMenu.cshtml index 39611a314e..c2824be334 100644 --- a/samples/StandaloneApp/Shared/NavMenu.cshtml +++ b/samples/StandaloneApp/Shared/NavMenu.cshtml @@ -1,5 +1,5 @@