Ionic-framework: Remove # from DeepLinker generated URL

Created on 3 Apr 2017  路  17Comments  路  Source: ionic-team/ionic-framework

Ionic version: (check one with "x")
[ ] 1.x
[x ] 2.x

I'm submitting a ... (check one with "x")
[ x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:
A number sign (#) is added inside the URL when using DeepLinker. This sign shouldn't be in URL, and make it harder for search engines to index the current page.
Example of URL: http://localhost:8100/#/my-page

Expected behavior:
The page URL shouldn't include number sign
http://localhost:8100/my-page

Steps to reproduce:
Irrelevant

Related code:

{links: [
        { component: MyPage, name: 'My Page', segment: 'my-page' },
      ]}

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

C ordova CLI: 6.5.0
Ionic Framework Version: 2.3.0
Ionic CLI Version: 2.2.2
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.2.2
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.9.2
Xcode version: Not installed

Most helpful comment

I just ran into this issue. You can do this at app.module.ts:

```
import { LocationStrategy, PathLocationStrategy } from '@angular/common';

@NgModule({
providers: [
{ provide: LocationStrategy, useClass: PathLocationStrategy },
]
});
````

All 17 comments

Config.locationStrategy looks relevant.

Hello, thanks for opening an issue with us. By default we use the hashbang style of URL's (kinda like the old angularjs router), but you can use the config @rapropos posted about to change that. Thanks @rapropos !

what should i do with locationStrategy? I can't find any on docs neither on other website...to eliminate # on deeplink

I just ran into this issue. You can do this at app.module.ts:

```
import { LocationStrategy, PathLocationStrategy } from '@angular/common';

@NgModule({
providers: [
{ provide: LocationStrategy, useClass: PathLocationStrategy },
]
});
````

The above still doesnt solve the issue. I added this but get a "Cannot Get /page-name" on every page accept the homepage. Do i need to setup some sort of .htaccess file for ionic serve?
How do i fix this??

Same here

@kienpham2000 after using this the hash sing has been remove from the url but when we are trying to open page with newly generated url then this is return to and error page something like this :Not Found
The requested URL /shop-collection/gamcha-tales-8849 was not found on this server. so please tell me how to resolve this

Same here

this is still open, sorry

after spend some time on RND finally got the ans set LocationStrategy:'path' this will remove hash from URL after removing hash enable mod_rewrite into your server if you are using Apache then past the following code into your server config file


Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all

after enable the mod_rewrite add these line into your .htaccess file

Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

But how do you do this @coder-hunt if you are using s3 buckets for the app? Where do we set LocationStrategy?

how to use when we are using lazy loading
it not working.

any one please help me to resolve in lazy loading

@ipehimanshu . I am stuck on this issue.

@MichaelHuy
still i have not got any solution

@rapropos @jgw96 how to use when we are using lazy loading
it not working.
any one please help me to resolve in lazy loading? Thanks.

why is this issue closed when it is unresolved?

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fdnhkj picture fdnhkj  路  3Comments

danbucholtz picture danbucholtz  路  3Comments

alexbainbridge picture alexbainbridge  路  3Comments

SebastianGiro picture SebastianGiro  路  3Comments

giammaleoni picture giammaleoni  路  3Comments