# PathLocationStrategy with DeepLinker

**URL:** <https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287>\
**Category:** ionic-v3\
**Created:** [November 5, 2016, 5:49pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287 "2016-11-05T17:49:40Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jczaplewski](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jczaplewski/32/84905_2.png) [@jczaplewski](https://forum.ionicframework.com/u/jczaplewski)\
**Post date:** [November 5, 2016, 5:49pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/1 "2016-11-05T17:49:40Z")

</div>

I’m working on building a web app with Ionic 2 and obviously need direct links to many of the pages. I am using the new [DeepLinker](http://ionicframework.com/docs/v2/api/navigation/DeepLinker/) to enable this, but it uses the old HashLocationStrategy by default. Is there anyway to use the PathLocationStrategy instead? For example, instead of [example.com/#/contact](http://example.com/#/contact) I would like to see [example.com/contact](http://example.com/contact)

---

<div class="post-metadata">

**Author:** ![arobertsztech](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@arobertsztech](https://forum.ionicframework.com/u/arobertsztech)\
**Post date:** [November 5, 2016, 9:21pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/2 "2016-11-05T21:21:38Z")

</div>

config.get(‘locationStrategy’) === ‘path’ is in the src.

IonicModule.forRoot(AppComponent, { locationStrategy: ‘path’ }, DEEP\_LINK\_CONFIG)

should work.

---

<div class="post-metadata">

**Author:** ![jczaplewski](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jczaplewski/32/84905_2.png) [@jczaplewski](https://forum.ionicframework.com/u/jczaplewski)\
**Post date:** [November 7, 2016, 1:29am UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/3 "2016-11-07T01:29:46Z")

</div>

Thanks! That is definitely on the right path. It is obvious in the source code that it is the right parameter - [https://github.com/driftyco/ionic/blob/f87c1fee5e1938be7f8535a68df141af109ea680/src/module.ts#L200](https://github.com/driftyco/ionic/blob/f87c1fee5e1938be7f8535a68df141af109ea680/src/module.ts#L200)

I tried the following with no success:

```
  imports: [
    IonicModule.forRoot(MyApp, {
       locationStrategy: 'path'
     }, {
    links: [
        { component: ContactPage, name: 'Contact', segment: 'contact' },
        { component: AboutPage, name: 'about', segment: 'about'},
        { component: HomePage, name: 'Home', segment: ''}
    ]
  })
]

```

When I go to the root, the home page is served, but if I go to `/contact` I get an error. Am I missing something else? It also seems that the `locationStrategy` is not documented in the Config documentation - [https://ionicframework.com/docs/v2/api/config/Config/](https://ionicframework.com/docs/v2/api/config/Config/)

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [November 7, 2016, 5:53pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/4 "2016-11-07T17:53:31Z")

</div>

Do you have the base href set in the index.html?

I’ll admit that the deeplinker docs need some more attention in this aspect, something I will be working on this week.

---

<div class="post-metadata">

**Author:** ![jczaplewski](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jczaplewski/32/84905_2.png) [@jczaplewski](https://forum.ionicframework.com/u/jczaplewski)\
**Post date:** [November 7, 2016, 6:39pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/5 "2016-11-07T18:39:01Z")

</div>

Yes, I have it set as so in the `<head>` - `<base href="/">`

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [November 7, 2016, 9:11pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/6 "2016-11-07T21:11:49Z")

</div>

whats the error that you actually get? Maybe that will help

---

<div class="post-metadata">

**Author:** ![jczaplewski](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jczaplewski/32/84905_2.png) [@jczaplewski](https://forum.ionicframework.com/u/jczaplewski)\
**Post date:** [November 7, 2016, 10:07pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/7 "2016-11-07T22:07:44Z")

</div>

I ended up getting it to work - [http://plnkr.co/edit/syUH0d6SJd2gAjqaPLwr?p=preview](http://plnkr.co/edit/syUH0d6SJd2gAjqaPLwr?p=preview)

---

<div class="post-metadata">

**Author:** ![vtulin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vtulin/32/106995_2.png) [@vtulin](https://forum.ionicframework.com/u/vtulin)\
**Post date:** [February 17, 2017, 12:30pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/8 "2017-02-17T12:30:19Z")

</div>

Doesn’t work anymore?

---

<div class="post-metadata">

**Author:** ![mdlallemont](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mdlallemont/32/64828_2.png) [@mdlallemont](https://forum.ionicframework.com/u/mdlallemont)\
**Post date:** [February 17, 2017, 2:13pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/9 "2017-02-17T14:13:16Z")

</div>

I just tried doing everything you did and it still doesn’t work. I receive the “Cannot GET /team-member-admin” error when I refresh the URL “[http://localhost:8100/team-member-admin](http://localhost:8100/team-member-admin)” where “team-member-admin” is my segment name for the TeamMemberAdmin component.

I have PathLocationStrategy set and base ref set to “/” or in this case to your script write. Neither work for me.

---

<div class="post-metadata">

**Author:** ![vtulin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vtulin/32/106995_2.png) [@vtulin](https://forum.ionicframework.com/u/vtulin)\
**Post date:** [February 17, 2017, 5:05pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/10 "2017-02-17T17:05:20Z")

</div>

Give us some real code, it works for me, not as I expected, but no errors.

---

<div class="post-metadata">

**Author:** ![mdlallemont](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mdlallemont/32/64828_2.png) [@mdlallemont](https://forum.ionicframework.com/u/mdlallemont)\
**Post date:** [February 17, 2017, 6:12pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/11 "2017-02-17T18:12:20Z")

</div>

What exactly do you mean “it works for me, not as expected?”

---

<div class="post-metadata">

**Author:** ![vtulin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vtulin/32/106995_2.png) [@vtulin](https://forum.ionicframework.com/u/vtulin)\
**Post date:** [February 19, 2017, 11:34am UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/12 "2017-02-19T11:34:30Z")

</div>

I was trying to make a global header working, so it was a single PageComponent, which checks the DeepLinker and loads the content from other component dynamically. So in my case it was:  
`links: [{ component: PageComponent, name: 'Contact', segment: 'contact' }, { component: PageComponent, name: 'about', segment: 'about'}, { component: PageComponent, name: 'Home', segment: 'last'}]`

But that didn’t work, the component of the page has some back relation to it’s segment, and when I run this any segment redirects to the last link in links.  
That’s what I mean about not as I expected, but when segments contain different components everything works fine, both ways: hash and path.

---

<div class="post-metadata">

**Author:** ![jczaplewski](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jczaplewski/32/84905_2.png) [@jczaplewski](https://forum.ionicframework.com/u/jczaplewski)\
**Post date:** [February 20, 2017, 2:16pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/13 "2017-02-20T14:16:04Z")

</div>

It’s important to note that the path location strategy won’t work as expected when used with `ionic serve` or anything similar. When developing, I use a hash location strategy, but in production we have a special block in our nginx configuration that makes the path location strategy work.

```
location ~ ^/(contact|about|home|some-other-page) {
    try_files $uri $uri/ /directory-where-pwa-lives/index.html;
}

```

Hope that helps!

---

<div class="post-metadata">

**Author:** ![ClearCostHealth](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@ClearCostHealth](https://forum.ionicframework.com/u/ClearCostHealth)\
**Post date:** [January 20, 2020, 8:21pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/14 "2020-01-20T20:21:53Z")

</div>

This app-scripts http-server.ts edit works for me in combination with `<base href="/" />`.

> <https://github.com/ionic-team/ionic/issues/10565#issuecomment-307420460>
>
> Ionic version: (check one with "x")
> \[\] 1.x
> \[X\] 2.x
> I'm submitting a ... (check one with "x")
> \[X\] bug report
> \[\] feature request
> \[...

I put in a PR for @ionic/app-scripts 3.2.5:

> <https://github.com/ionic-team/ionic-app-scripts/pull/1545>

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:01pm UTC](https://forum.ionicframework.com/t/pathlocationstrategy-with-deeplinker/69287/15 "2021-07-19T21:01:54Z")

</div>


