Skip to content

pushStateLocationPlugin does not recognize initial url #223

Closed
@afoninv

Description

@afoninv

(issue moved from ui-router/react repo, where it originally surfaced)

Seems like, when using pushStateLocationPlugin, whatever location user enters into browser address bar gets ignored by router (depending on configuration, this either redirects you to default state, or gets you nowhere at all).

Steps to reproduce:

  1. clone ui-router/react repo
  2. modify examples/animating-transitions/index.js to use pushStateLocationPlugin instead of hashLocationPlugin:
    ...
4.  import { UIRouter, UIView, pushStateLocationPlugin } from '@uirouter/react';
    ...
25. <UIRouter plugins={[pushStateLocationPlugin]} states={states} config={config}>
  1. cd examples/animating-transitions && npm i && npm start
  2. enter into browser address bar http://localhost:3000/about
  3. get redirected to /home instead

If you disable initial rule on line 22, you won't even get to home state.
Using links works as intended.
hashLocationPlugin works as intended.

Latest version where pushStateLocationPlugin actually works seems to be 0.5.5 . Discovered this bug when trying to upgrade to newest @uirouter/react version

===

After some investigation, it looks like the offender is this commit: 0251424 .
In absence of <base> tag, it sets baseHref to location.href at the time of router initialization (changed in subsequent commits to location.pathname, but that does not fix the problem in question). This is OK if we use hashLocation, but for pushStateLocation this means, whatever url was originally entered into browser address bar, becomes baseHref.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions