Skip to content

HTML5LocationStrategy fails to update path on router.navigate #3096

Closed

Description

@bryantharpe

It appears that only the HashLocationStrategy updates the url on calls to router.navigate. When I change my LocationStrategy to the HTML5LocationStrategy the urls no longer update when navigating from "/products/:productId" -> "/". The navigation does occur, though.

This is happening on Alpha.31.

The code I'm using is below.

Component Controller code

    updateProduct(product: {productId:string, name:string, description:string}) {
        this.productStore.updateProduct(product);

        this.router.navigate('/');
    }

Routes

@RouteConfig([
    {path: '/', component: ProductsList, as: 'Products'},
    {path: '/products/:productId', component: UpdateProducts, as: 'UpdateProducts'}
])

Bootstrap

import { httpInjectables } from 'angular2/http';
import { bootstrap, bind } from 'angular2/angular2';
import { routerInjectables, LocationStrategy, HashLocationStrategy, HTML5LocationStrategy } from 'angular2/router';
import { Onboarding } from './components/onboarding/onboarding';


bootstrap(Onboarding, [
    httpInjectables,routerInjectables, bind(LocationStrategy).toClass(HTML5LocationStrategy )
]);

Activity

  1. Zyzle commented on Jul 16, 2015

    @Zyzle

    Does your entry point page specify a <base> tag? I found similar behaviour a few milestones back (~28 I think) when my app didn't have the base tag.

    Edit: Just went back and tried this in my app and yes removing the base tag causes this issue.

    @RouteConfig([
      { path: "/", as: "home", component: HomePage },
      { path: "/formtest", as: "formtest", component: FormTest },
      { path: "/ghrepos", as: "ghrepos", component: GhRepos }
    ])
    

    Navigation between routes works however attempting to go back to the / route updates the page components but not the URL

  2. bryantharpe commented on Jul 16, 2015

    @bryantharpe
    Author

    Thanks for the tip. I just added a base tag and it works now. Is that always going to be required for the HTML5 Strategy? Not exactly hard to add to the page, so, not that big of a deal.

  3. added this to the alpha-33 milestone on Jul 17, 2015
  4. self-assigned this
    on Jul 17, 2015
  5. btford commented on Jul 17, 2015

    @btford
    Contributor

    @bryantharpe you either have to add a <base> tag or set an app base href like this: https://github.com/angular/angular/blob/master/modules/angular2/test/router/router_integration_spec.ts#L78-L90

    Currently the router uses document.baseURI to determine the base URI. I think it might be better to remove this option entirely and make the app base href binding required.

  6. bryantharpe commented on Jul 17, 2015

    @bryantharpe
    Author

    Thanks for the input @btford That makes more sense, I went ahead and updated my code to work like that.

  7. modified the milestones: alpha-33, alpha-32 on Jul 17, 2015
  8. angular-automatic-lock-bot commented on Sep 6, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions