1

I am using Angular 6 my am some getting some issue while deploy application on tomcat

i have Base href = /login/

when i go to any page like you see below forget routerlink it work but when i refresh or directly open http:localhost:8088/login/forget it will not display this page its showing serve issue like 2 image

enter image description here

This is After reload the page

enter image description here In Development mode everything working fine without any error

Step that i use to deploy aplication

  1. 1.ng build --prod --base-href /login/
  2. copy dist folder files
  3. go Apache Software Foundation\Tomcat 8.5\webapps\ and create login folder
  4. paste all dist folder file into tomcat login folder like below you can see
  5. start tomcat sever

enter image description here

5
  • Possible duplicate of Angular2 routing / deep linking not working with Apache 404 Commented May 20, 2019 at 7:12
  • @BearNithi i am not talking about image issue i have issue when u reload page it not working Commented May 20, 2019 at 7:13
  • @FatemeFazli can you please help me Commented May 20, 2019 at 7:44
  • based on link above did you add .htaccess file? Commented May 20, 2019 at 7:48
  • @FatemeFazli i tryed but its does not work Commented May 20, 2019 at 7:53

3 Answers 3

1

I am using this in “app.module.ts” (check this link where I got some help: "https://medium.com/tinywave/angular-6-404-error-during-refresh-after-deployed-8cec7140b584")

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

providers: [
            {provide : LocationStrategy , useClass: HashLocationStrategy}
           ],

After that import, the site works well and call the spring services, but, I have a reload for CRUD in the same page and there is the same thing.

Sign up to request clarification or add additional context in comments.

Comments

0

Just copy all these files and paste them in /angular folder under /webapps folder in tomcat.

Once copied, fire up the server and visit localhost:8080/angular/index.html and our bikes app should be seen running.

=====OR=======

Open the index.html file, replace the base-href=”/angular/” with base-href=”.” and restart the tomcat and access the url.

Or

For each of the script tag, in src tag add “angular/” e.g.

All doing any of the change suggested, refresh the page in browser. Error will be gone.

Comments

0

The application deep links will not work without the redirect rule on the server. All the deep links have to redirect to the application index.html by the server.

To setup the tomcat to redirect any deep links -

  1. Configure the RewriteValve in server.xml
  2. Write the rewrite rule in rewrite.config

1. Configure the RewriteValve in server.xml

Edit the ~/conf/server.xml to add the below Valve inside the Host section as below –

...
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />

...
      </Host>
...

2. Write the rewrite rule in rewrite.config

Create directory structure – ~/conf/Catalina/localhost/ and create the rewrite.config file inside it with the below content –

RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/login/(.*) /login/index.html

After setting this up restart the tomcat server and you can hit the deep links of the application which will route to the correct components inside the angular application.

You can refer to this post for more details.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.