Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.

Clean up use of relative URLs. Fixes #844 and #845 - #878

Merged
SteveSandersonMS merged 5 commits into
devfrom
stevesa/relative-urls-cleanup
May 24, 2018
Merged

SteveSandersonMS merged 5 commits into
devfrom
stevesa/relative-urls-cleanup

Conversation

@SteveSandersonMS

Copy link
Copy Markdown
Member

Previously we were handling relative URLs in various inconsistent ways. Sometimes they were assumed to start with slashes, and other times they were assumed not to do so. Likewise, APIs that were meant to match or return relative URLs did inconsistent things.

In this PR I've done a pass through (hopefully) everything that is or handles relative URLs, standardizing on a consistent pattern that:

  • Base URLs always have a trailing slash (just like a <base href> value must do, if it's going to behave as people expect)
  • Base-relative URLs do not have a leading slash (because if they did, they are root-relative not base-relative)

There are still a couple of edge cases:

  • If your site has the base href /somedir/, we want anyone visiting http://yoursite/somedir to be treated the same as if they were visiting http://yoursite/somedir/ (i.e., so the same page would be selected and the same nav links would be highlighted). That's because devs often don't have control over the webserver config and might not be able to enforce the trailing slash as canonical.
  • With the @page directive, people will still typically give values with leading-slashes (e.g., @page "/", not @page ""). We ignore the presence or absence of a leading slash there, because it could never have any meaning, and because people will find it hard to understand what an empty string value would mean.

Altogether this fixes #844 and #845, plus is just more consistent internally.

@rynowak @javiercn I'm adding you for review, but I know the contents here won't be hugely interesting as it has limited overlap with your areas. Totally fine if you want to ignore this - I'll just merge it tomorrow unless anyone raises specific concerns.

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)
Hence also change terminology from "base URI prefix" to simply "base URI"
@SteveSandersonMS SteveSandersonMS added this to the 0.4.0 milestone May 23, 2018
@SteveSandersonMS
SteveSandersonMS merged commit d953618 into dev May 24, 2018
@SteveSandersonMS
SteveSandersonMS deleted the stevesa/relative-urls-cleanup branch May 24, 2018 08:54
SteveSandersonMS added a commit to SteveSandersonMS/BlazorMigration that referenced this pull request Nov 27, 2018
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant