Angular2 routing - adding the hashtag using LocationStrategy not working?

前端 未结 2 1565
清酒与你
清酒与你 2020-12-21 03:54

I\'m following the simple quickstart app from the Angular2 docs and I\'m using a spring backend to run it. My problem is that the angular router ditched the hashtag from the

2条回答
  •  轮回少年
    2020-12-21 04:52

    Angular2 <= RC.5

    The ROUTER_PROVIDERS need to be added before LocationStrategy otherwise your previously added LocationStrategy gets overridden.

    bootstrap(
        TestComponent, 
        [
            ROUTER_PROVIDERS, 
            // must be listed after `ROUTER_PROVIDERS`
            provide(LocationStrategy, { useClass: HashLocationStrategy })
        ]
    );
    

    delete this line

    providers: [ROUTER_PROVIDERS]
    

    from TestComponent

提交回复
热议问题