路由不适用于 "blog/ :page" 的生产
routing does not works on production for "blog/ :page"
我正在学习 angular 并且正在尝试为自己建立一个博客网站。当我 运行 使用
时,该网站在我的本地系统上按预期工作
ng serve
但另一方面,当我创建它的构建并使用
将其上传到生产环境时
ng build --prod
路由不起作用。我在我的服务器
上添加了 .htaccess
中的代码
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
路由开始为
工作
但
仍然失败
http://www.atest.co.in/blog/Manual_Testing%2FIs_Manual_Testing_Dying
以上路由设置如下:
{
path: 'blog',
component: BlogComponent
},
{
path: 'blog/:page',
component: BlogComponent
}
尽管后者在 localhost
上运行良好
已更新
根据您的代码,这只是静态 html 文件加载。但是你问题中的路由在文件名中有一个 /
,它被编码为 %2F
。我认为直接路由时会出错。如果您先访问 http://www.atest.co.in/blog/,然后单击边栏中的 link,您将获得该页面。
删除文件名中的 %2F 字符,它会起作用。
我正在学习 angular 并且正在尝试为自己建立一个博客网站。当我 运行 使用
时,该网站在我的本地系统上按预期工作
ng serve
但另一方面,当我创建它的构建并使用
将其上传到生产环境时
ng build --prod
路由不起作用。我在我的服务器
上添加了.htaccess
中的代码
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
路由开始为
工作但
仍然失败http://www.atest.co.in/blog/Manual_Testing%2FIs_Manual_Testing_Dying
以上路由设置如下:
{
path: 'blog',
component: BlogComponent
},
{
path: 'blog/:page',
component: BlogComponent
}
尽管后者在 localhost
已更新
根据您的代码,这只是静态 html 文件加载。但是你问题中的路由在文件名中有一个 /
,它被编码为 %2F
。我认为直接路由时会出错。如果您先访问 http://www.atest.co.in/blog/,然后单击边栏中的 link,您将获得该页面。
删除文件名中的 %2F 字符,它会起作用。