Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML5LocationStrategy fails to update path on router.navigate #3096

Closed
bryantharpe opened this issue Jul 16, 2015 · 5 comments · Fixed by #3122
Closed

HTML5LocationStrategy fails to update path on router.navigate #3096

bryantharpe opened this issue Jul 16, 2015 · 5 comments · Fixed by #3122

Comments

@bryantharpe
Copy link

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 )
]);
@Zyzle
Copy link

Zyzle commented Jul 16, 2015

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

@bryantharpe
Copy link
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.

@btford
Copy link
Contributor

btford commented Jul 17, 2015

@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.

@bryantharpe
Copy link
Author

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

btford added a commit to btford/angular that referenced this issue Jul 17, 2015
btford added a commit to btford/angular that referenced this issue Jul 17, 2015
btford added a commit to btford/angular that referenced this issue Jul 17, 2015
btford added a commit to btford/angular that referenced this issue Jul 17, 2015
btford added a commit to btford/angular that referenced this issue Jul 17, 2015
btford added a commit to btford/angular that referenced this issue Jul 17, 2015
@btford btford modified the milestones: alpha-33, alpha-32 Jul 17, 2015
NathanWalker referenced this issue in PatrickJS/PatrickJS-starter Jul 23, 2015
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants