Skip to content

Router: Failed to execute 'pushState' on 'History' error with PathLocationStrategy #6909

@mip1983

Description

@mip1983

I'm getting an error in my application (beta3, though I had this with earlier versions too) where I'm creating routing components with child routing.

I'm basically setting up my main app component to support different page layouts, so I have these routes in my main app component:

@RouteConfig([
    { path: "/...", name: "Home", component: MainLayoutComponent, useAsDefault: true },
    { path: "/login/...", name: "Login", component: MinLayoutComponent }
])

Then my main layout component has any child components that use this layout:

@RouteConfig([
        { path: "/dashboard/...", name: "Dashboard", component: DashboardComponent, useAsDefault: true }
])
export class MainLayoutComponent {

}

With hashlocation strategy in plunker this works fine. With default pathLocation strategy (which I can't get working in plunker but am using locally) I get a:

Failed to execute 'pushState' on 'History'

If I change the '/...' path in my main app component to '/app/...' all works fine (except I don't have the url I want).

I've created a plunker example of my setup, but I've not been able to repro in plunker because I don't think I can use the pathLocation strategy there. If you download this plunker, remove hashlocation strategy and host locally you may be able to reproduce:

https://plnkr.co/edit/P6Bkwy?p=preview

Exception snippet:

EXCEPTION: SecurityError: Failed to execute 'pushState' on 'History': A history state object with URL 'http://dashboard/' cannot be created in a document with origin 'http://localhost:59849'.BrowserDomAdapter.logError @ angular2.dev.js:22911
angular2.dev.js:22911 STACKTRACE:BrowserDomAdapter.logError @ angular2.dev.js:22911
angular2.dev.js:22911 Error: Failed to execute 'pushState' on 'History': A history state object with URL 'http://dashboard/' cannot be created in a document with origin 'http://localhost:59849'.
at Error (native)
at BrowserPlatformLocation.pushState (http://localhost:59849/lib/angular2/router.dev.js:2102:21)
at PathLocationStrategy.pushState (http://localhost:59849/lib/angular2/router.dev.js:1247:30)
at Location.go (http://localhost:59849/lib/angular2/router.dev.js:1829:29)
at http://localhost:59849/lib/angular2/router.dev.js:2989:27
at e.run (http://localhost:59849/lib/angular2/angular2-polyfills.min.js:1:8725)
at e.run (http://localhost:59849/lib/angular2/angular2.dev.js:13408:32)
at http://localhost:59849/lib/angular2/angular2-polyfills.min.js:1:8372
at x (http://localhost:59849/lib/angular2/angular2-polyfills.min.js:1:3172)
at F (http://localhost:59849/lib/angular2/angular2-polyfills.min.js:1:3258)
at A (http://localhost:59849/lib/angular2/angular2-polyfills.min.js:1:3075)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions