Repository: phoenixframework/phoenix
Pull request #4904 (2022-07-29 14:32:49)

Update generators for verified routes


Patch:
diff --git a/installer/templates/phx_single/config/dev.exs b/installer/templates/phx_single/config/dev.exs
index b1cc681e4..85f8e2df9 100644
--- a/installer/templates/phx_single/config/dev.exs
+++ b/installer/templates/phx_single/config/dev.exs
@@ -54,6 +54,9 @@ config :<%= @app_name %>, <%= @endpoint_module %>,
     ]
   ]<% end %>
 
+# Enable dev routes for dashboard and mailbox
+config :<%= @app_name %>, dev_routes: true
+
 # Do not include metadata nor timestamps in development logs
 config :logger, :console, format: "[$level] $message\n"
 
diff --git a/installer/templates/phx_single/lib/app_name_web.ex b/installer/templates/phx_single/lib/app_name_web.ex
index 26309035b..ba43ac10c 100644
--- a/installer/templates/phx_single/lib/app_name_web.ex
+++ b/installer/templates/phx_single/lib/app_name_web.ex
@@ -17,13 +17,18 @@ defmodule <%= @web_namespace %> do
   and import those modules here.
   """
 
+  def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)
+
   def controller do
     quote do
       use Phoenix.Controller, namespace: <%= @web_namespace %>
+      use Phoenix.VerifiedRoutes,
+        endpoint: <%= @endpoint_module %>,
+        router: <%= @web_namespace %>.Router,
+        statics: <%= @web_namespace %>.static_paths()
 
       import Plug.Conn<%= if @gettext do %>
       import <%= @web_namespace %>.Gettext<% end %>
-      alias <%= @web_namespace %>.Router.Helpers, as: Routes
     end
   end
 
@@ -69,7 +74,7 @@ defmodule <%= @web_namespace %> do
 
   def router do
     quote do
-      use Phoenix.Router
+      use Phoenix.Router, helpers: false
 
       import Plug.Conn
       import Phoenix.Controller<%= if @html do %>
@@ -88,17 +93,25 @@ defmodule <%= @web_namespace %> do
     quote do<%= if @html do %>
       # Use all HTML functionality (forms, tags, etc)
       use Phoenix.HTML
+      use Phoenix.VerifiedRoutes,
+        endpoint: <%= @endpoint_module %>,
+        router: <%= @web_namespace %>.Router,
+        statics: <%= @web_namespace %>.static_paths()
 
       # Import LiveView and .heex helpers (live_render, <.link>, <.form>, etc)
       import Phoenix.LiveView.Helpers
+<% else %>
+      use Phoenix.VerifiedRoutes,
+        endpoint: <%= @endpoint_module %>,
+        router: <%= @web_namespace %>.Router,
+        statics: <%= @web_namespace %>.static_paths()
 <% end %>
       # Import basic rendering functionality (render, render_layout, etc)
       import Phoenix.View
 
       import <%= @web_namespace %>.ErrorHelpers<%= if @gettext do %>
-      import <%= @web_namespace %>.Gettext<% end %>
-      alias <%= @web_namespace %>.Router.Helpers, as: Routes
-      alias Phoenix.LiveView.JS
+      import <%= @web_namespace %>.Gettext<% end %><%= if @html do %>
+      alias Phoenix.LiveView.JS<% end %>
     end
   end
 
diff --git a/installer/templates/phx_umbrella/apps/app_name_web/lib/app_name.ex b/installer/templates/phx_umbrella/apps/app_name_web/lib/app_name.ex
index 1abf6ecea..6d102da8c 100644
--- a/installer/templates/phx_umbrella/apps/app_name_web/lib/app_name.ex
+++ b/installer/templates/phx_umbrella/apps/app_name_web/lib/app_name.ex
@@ -17,9 +17,15 @@ defmodule <%= @web_namespace %> do
   and import those modules here.
   """
 
+  def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)
+
   def controller do
     quote do
       use Phoenix.Controller, namespace: <%= @web_namespace %>
+      use Phoenix.VerifiedRoutes,
+        endpoint: <%= @endpoint_module %>,
+        router: <%= @web_namespace %>.Router,
+        statics: <%= @web_namespace %>.static_paths()
 
       import Plug.Conn<%= if @gettext do %>
       import <%= @web_namespace %>.Gettext<% end %>
@@ -88,17 +94,25 @@ defmodule <%= @web_namespace %> do
     quote do<%= if @html do %>
       # Use all HTML functionality (forms, tags, etc)
       use Phoenix.HTML
+      use Phoenix.VerifiedRoutes,
+        endpoint: <%= @endpoint_module %>,
+        router: <%= @web_namespace %>.Router,
+        statics: <%= @web_namespace %>.static_paths()
 
       # Import LiveView and .heex helpers (live_render, <.link>, <.form>, etc)
       import Phoenix.LiveView.Helpers
 <% end %>
+      use Phoenix.VerifiedRoutes,
+        endpoint: <%= @endpoint_module %>,
+        router: <%= @web_namespace %>.Router,
+        statics: <%= @web_namespace %>.static_paths()
+
       # Import basic rendering functionality (render, render_layout, etc)
       import Phoenix.View
 
       import <%= @web_namespace %>.ErrorHelpers<%= if @gettext do %>
-      import <%= @web_namespace %>.Gettext<% end %>
-      alias <%= @web_namespace %>.Router.Helpers, as: Routes
-      alias Phoenix.LiveView.JS
+      import <%= @web_namespace %>.Gettext<% end %><%= if @html do %>
+      alias Phoenix.LiveView.JS<% end %>
     end
   end
 
diff --git a/installer/templates/phx_web/endpoint.ex b/installer/templates/phx_web/endpoint.ex
index 1f42e1d2f..d9ec4b36c 100644
--- a/installer/templates/phx_web/endpoint.ex
+++ b/installer/templates/phx_web/endpoint.ex
@@ -21,7 +21,7 @@ defmodule <%= @endpoint_module %> do
     at: "/",
     from: :<%= @web_app_name %>,
     gzip: false,
-    only: ~w(assets fonts images favicon.ico robots.txt)
+    only: <%= @web_namespace %>.static_paths()
 
   # Code reloading can be explicitly enabled under the
   # :code_reloader configuration of your endpoint.
diff --git a/installer/templates/phx_web/router.ex b/installer/templates/phx_web/router.ex
index 29dabb4a1..9e67a2dca 100644
--- a/installer/templates/phx_web/router.ex
+++ b/installer/templates/phx_web/router.ex
@@ -27,16 +27,15 @@ defmodule <%= @web_namespace %>.Router do
 
   scope "/api", <%= @web_namespace %> do
     pipe_through :api
-  end<% end %><%= if @dashboard do %>
-
-  # Enables LiveDashboard only for development
-  #
-  # If you want to use the LiveDashboard in production, you should put
-  # it behind authentication and allow only admins to access it.
-  # If your application does not have an admins-only section yet,
-  # you can use Plug.BasicAuth to set up some basic authentication
-  # as long as you are also using SSL (which you should anyway).
-  if Mix.env() in [:dev, :test] do
+  end<% end %><%= if @dashboard || @mailer do %>
+
+  # Enable <%= [@dashboard && "LiveDashboard", @mailer && "Swoosh mailbox preview"] |> Enum.filter(&(&1)) |> Enum.join(" and ") %> in development
+  if Application.compile_env(:<%= @app_name %>, :dev_routes, false) do<% end %><%= if @dashboard do %>
+    # If you want to use the LiveDashboard in production, you should put
+    # it behind authentication and allow only admins to access it.
+    # If your application does not have an admins-only section yet,
+    # you can use Plug.BasicAuth to set up some basic authentication
+    # as long as you are also using SSL (which you should anyway).
     import Phoenix.LiveDashboard.Router
 
     scope "/" do<%= if @html do %>
@@ -45,13 +44,7 @@ defmodule <%= @web_namespace %>.Router do
 
       live_dashboard "/dashboard", metrics: <%= @web_namespace %>.Telemetry
     end
-  end<% end %><%= if @mailer do %>
-
-  # Enables the Swoosh mailbox preview in development.
-  #
-  # Note that preview only shows emails that were sent by the same
-  # node running the Phoenix server.
-  if Mix.env() == :dev do
+  <% end %><%= if @mailer do %>
     scope "/dev" do<%= if @html do %>
       pipe_through :browser<% else %>
       pipe_through [:fetch_session, :protect_from_forgery]<% end %>
diff --git a/installer/templates/phx_web/templates/layout/root.html.heex b/installer/templates/phx_web/templates/layout/root.html.heex
index a87e52978..e649a600d 100644
--- a/installer/templates/phx_web/templates/layout/root.html.heex
+++ b/installer/templates/phx_web/templates/layout/root.html.heex
@@ -6,8 +6,8 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
     <meta name="csrf-token" content={get_csrf_token()}>
     <%%= live_title_tag assigns[:page_title] || "<%= @app_module %>", suffix: " · Phoenix Framework" %>
-    <link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/assets/app.css")}/>
-    <script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/assets/app.js")}></script>
+    <link phx-track-static rel="stylesheet" href={~p"/assets/app.css"}/>
+    <script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}></script>
   </head>
   <body>
     <header>
@@ -16,12 +16,12 @@
           <ul>
             <li><a href="https://hexdocs.pm/phoenix/overview.html">Get Started</a></li>
             <%= if @dashboard do %><%%= if function_exported?(Routes, :live_dashboard_path, 2) do %>
-              <li><.link href={Routes.live_dashboard_path(@conn, :home)}>LiveDashboard</.link></li>
+              <li><.link href={~p"/dashboard"}>LiveDashboard</.link></li>
             <%% end %><% end %>
           </ul>
         </nav>
         <a href="https://phoenixframework.org/" class="phx-logo">
-          <img src={Routes.static_path(@conn, "/images/phoenix.png")} alt="Phoenix Framework Logo"/>
+          <img src={~p"/images/phoenix.png"} alt="Phoenix Framework Logo"/>
         </a>
       </section>
     </header>
diff --git a/lib/mix/phoenix/schema.ex b/lib/mix/phoenix/schema.ex
index 13bc26f35..3f8f01038 100644
--- a/lib/mix/phoenix/schema.ex
+++ b/lib/mix/phoenix/schema.ex
@@ -33,6 +33,8 @@ defmodule Mix.Phoenix.Schema do
             web_namespace: nil,
             context_app: nil,
             route_helper: nil,
+            route_path: nil,
+            api_route_path: nil,
             migration_module: nil,
             fixture_unique_functions: %{},
             fixture_params: %{},
@@ -81,6 +83,7 @@ defmodule Mix.Phoenix.Schema do
     types = types(attrs)
     web_namespace = opts[:web] && Phoenix.Naming.camelize(opts[:web])
     web_path = web_namespace && Phoenix.Naming.underscore(web_namespace)
+    api_prefix = Application.get_env(otp_app, :generators)[:api_prefix] || "/api"
     embedded? = Keyword.get(opts, :embedded, false)
     generate? = Keyword.get(opts, :schema, true)
 
@@ -132,6 +135,8 @@ defmodule Mix.Phoenix.Schema do
       web_namespace: web_namespace,
       web_path: web_path,
       route_helper: route_helper(web_path, singular),
+      route_path: route_path(web_path, schema_plural),
+      api_route_path: api_route_path(web_path, schema_plural, api_prefix),
       sample_id: sample_id(opts),
       context_app: ctx_app,
       generate?: generate?,
@@ -475,6 +480,16 @@ defmodule Mix.Phoenix.Schema do
     |> String.replace("/", "_")
   end
 
+  defp route_path(web_path, plural) do
+    path = Path.join(for str <- [web_path, plural], do: to_string(str))
+    "/" <> String.trim_leading(path, "/")
+  end
+
+  defp api_route_path(web_path, plural, api_prefix) do
+    path = Path.join(for str <- [api_prefix, web_path, plural], do: to_string(str))
+    "/" <> String.trim_leading(path, "/")
+  end
+
   defp migration_module do
     case Application.get_env(:ecto_sql, :migration_module, Ecto.Migration) do
       migration_module when is_atom(migration_module) -> migration_module
diff --git a/lib/mix/tasks/phx.gen.json.ex b/lib/mix/tasks/phx.gen.json.ex
index d7de31054..159cc5f49 100644
--- a/lib/mix/tasks/phx.gen.json.ex
+++ b/lib/mix/tasks/phx.gen.json.ex
@@ -32,6 +32,14 @@ defmodule Mix.Tasks.Phx.Gen.Json do
   A migration file for the repository and test files for the context and
   controller features will also be generated.
 
+  ## API Prefix
+
+  By default, the prefix "/api" will be generated for API route paths.
+  This can be customized via the `:api_prefix` generators configuration:
+
+      config :your_app, :generators,
+        api_prefix: "/api/v1"
+
   ## The context app
 
   The location of the web files (controllers, views, templates, etc) in an
diff --git a/priv/templates/phx.gen.html/controller.ex b/priv/templates/phx.gen.html/controller.ex
index a5cc45766..3bba60a32 100644
--- a/priv/templates/phx.gen.html/controller.ex
+++ b/priv/templates/phx.gen.html/controller.ex
@@ -19,7 +19,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
       {:ok, <%= schema.singular %>} ->
         conn
         |> put_flash(:info, "<%= schema.human_singular %> created successfully.")
-        |> redirect(to: Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))
+        |> redirect(to: ~p"<%= schema.route_path %>/#{<%= schema.singular %>}")
 
       {:error, %Ecto.Changeset{} = changeset} ->
         render(conn, "new.html", changeset: changeset)
@@ -44,7 +44,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
       {:ok, <%= schema.singular %>} ->
         conn
         |> put_flash(:info, "<%= schema.human_singular %> updated successfully.")
-        |> redirect(to: Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))
+        |> redirect(to: ~p"<%= schema.route_path %>/#{<%= schema.singular %>}")
 
       {:error, %Ecto.Changeset{} = changeset} ->
         render(conn, "edit.html", <%= schema.singular %>: <%= schema.singular %>, changeset: changeset)
@@ -57,6 +57,6 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
 
     conn
     |> put_flash(:info, "<%= schema.human_singular %> deleted successfully.")
-    |> redirect(to: Routes.<%= schema.route_helper %>_path(conn, :index))
+    |> redirect(to: ~p"<%= schema.route_path %>")
   end
 end
diff --git a/priv/templates/phx.gen.html/edit.html.heex b/priv/templates/phx.gen.html/edit.html.heex
index d0e188efa..ba55672b1 100644
--- a/priv/templates/phx.gen.html/edit.html.heex
+++ b/priv/templates/phx.gen.html/edit.html.heex
@@ -1,5 +1,5 @@
 <h1>Edit <%= schema.human_singular %></h1>
 
-<%%= render "form.html", Map.put(assigns, :action, Routes.<%= schema.route_helper %>_path(@conn, :update, @<%= schema.singular %>)) %>
+<%%= render "form.html", Map.put(assigns, :action, ~p"<%= schema.route_path %>/#{@<%= schema.singular %>}") %>
 
-<span><.link href={Routes.<%= schema.route_helper %>_path(@conn, :index)}>Back</.link></span>
+<span><.link href={~p"<%= schema.route_path %>"}>Back</.link></span>
diff --git a/priv/templates/phx.gen.html/index.html.heex b/priv/templates/phx.gen.html/index.html.heex
index b76291d77..1bc536227 100644
--- a/priv/templates/phx.gen.html/index.html.heex
+++ b/priv/templates/phx.gen.html/index.html.heex
@@ -14,13 +14,13 @@
 <%= for {k, _} <- schema.attrs do %>      <td><%%= <%= schema.singular %>.<%= k %> %></td>
 <% end %>
       <td>
-        <span><.link href={Routes.<%= schema.route_helper %>_path(@conn, :show, <%= schema.singular %>)}>Show</.link></span>
-        <span><.link href={Routes.<%= schema.route_helper %>_path(@conn, :edit, <%= schema.singular %>)}>Edit</.link></span>
-        <span><.link href={Routes.<%= schema.route_helper %>_path(@conn, :delete, <%= schema.singular %>)} method="delete" data-confirm="Are you sure?">Delete</.link></span>
+        <span><.link href={~p"<%= schema.route_path %>/#{<%= schema.singular %>}"}>Show</.link></span>
+        <span><.link href={~p"<%= schema.route_path %>/#{<%= schema.singular %>}/edit"}>Edit</.link></span>
+        <span><.link href={~p"<%= schema.route_path %>/#{<%= schema.singular %>}"} method="delete" data-confirm="Are you sure?">Delete</.link></span>
       </td>
     </tr>
 <%% end %>
   </tbody>
 </table>
 
-<span><.link href={Routes.<%= schema.route_helper %>_path(@conn, :new)}>New <%= schema.human_singular %></.link></span>
+<span><.link href={~p"<%= schema.route_path %>/new"}>New <%= schema.human_singular %></.link></span>
diff --git a/priv/templates/phx.gen.html/new.html.heex b/priv/templates/phx.gen.html/new.html.heex
index faa995622..2c3ebbdc4 100644
--- a/priv/templates/phx.gen.html/new.html.heex
+++ b/priv/templates/phx.gen.html/new.html.heex
@@ -1,5 +1,5 @@
 <h1>New <%= schema.human_singular %></h1>
 
-<%%= render "form.html", Map.put(assigns, :action, Routes.<%= schema.route_helper %>_path(@conn, :create)) %>
+<%%= render "form.html", Map.put(assigns, :action, ~p"<%= schema.route_path %>") %>
 
-<span><.link href={Routes.<%= schema.route_helper %>_path(@conn, :index)}>Back</.link></span>
+<span><.link href={~p"<%= schema.route_path %>"}>Back</.link></span>
diff --git a/priv/templates/phx.gen.html/show.html.heex b/priv/templates/phx.gen.html/show.html.heex
index 25c1f433a..41a298145 100644
--- a/priv/templates/phx.gen.html/show.html.heex
+++ b/priv/templates/phx.gen.html/show.html.heex
@@ -9,5 +9,5 @@
 <% end %>
 </ul>
 
-<span><.link href={Routes.<%= schema.route_helper %>_path(@conn, :edit, @<%= schema.singular %>)}>Edit</.link></span> |
-<span><.link href={Routes.<%= schema.route_helper %>_path(@conn, :index)}>Back</.link></span>
+<span><.link href={~p"<%= schema.route_path %>/#{@<%= schema.singular %>}/edit"}>Edit</.link></span> |
+<span><.link href={~p"<%= schema.route_path %>"}>Back</.link></span>
diff --git a/priv/templates/phx.gen.json/controller.ex b/priv/templates/phx.gen.json/controller.ex
index 1eb81e554..d38151610 100644
--- a/priv/templates/phx.gen.json/controller.ex
+++ b/priv/templates/phx.gen.json/controller.ex
@@ -15,7 +15,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
     with {:ok, %<%= inspect schema.alias %>{} = <%= schema.singular %>} <- <%= inspect context.alias %>.create_<%= schema.singular %>(<%= schema.singular %>_params) do
       conn
       |> put_status(:created)
-      |> put_resp_header("location", Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))
+      |> put_resp_header("location", ~p"<%= schema.api_route_path %>/#{<%= schema.singular %>}")
       |> render("show.json", <%= schema.singular %>: <%= schema.singular %>)
     end
   end
diff --git a/priv/templates/phx.gen.live/index.html.heex b/priv/templates/phx.gen.live/index.html.heex
index 65b9920da..e32b49b7b 100644
--- a/priv/templates/phx.gen.live/index.html.heex
+++ b/priv/templates/phx.gen.live/index.html.heex
@@ -1,14 +1,14 @@
 <h1>Listing <%= schema.human_plural %></h1>
 
 <%%= if @live_action in [:new, :edit] do %>
-  <.modal return_to={Routes.<%= schema.route_helper %>_index_path(@socket, :index)}>
+  <.modal return_to={~p"<%= schema.route_path %>"}>
     <.live_component
       module={<%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent}
       id={@<%= schema.singular %>.id || :new}
       title={@page_title}
       action={@live_action}
       <%= schema.singular %>={@<%= schema.singular %>}
-      return_to={Routes.<%= schema.route_helper %>_index_path(@socket, :index)}
+      return_to={~p"<%= schema.route_path %>"}
     />
   </.modal>
 <%% end %>
@@ -27,8 +27,8 @@
 <%= for {k, _} <- schema.attrs do %>        <td><%%= <%= schema.singular %>.<%= k %> %></td>
 <% end %>
         <td>
-          <span><.link navigate={Routes.<%= schema.route_helper %>_show_path(@socket, :show, <%= schema.singular %>)}>Show</.link></span>
-          <span><.link patch={Routes.<%= schema.route_helper %>_index_path(@socket, :edit, <%= schema.singular %>)}>Edit</.link></span>
+          <span><.link navigate={~p"<%= schema.route_path %>/#{<%= schema.singular %>}"}>Show</.link></span>
+          <span><.link patch={~p"<%= schema.route_path %>/#{<%= schema.singular %>}/edit"}>Edit</.link></span>
           <span><.link phx-click={JS.push("delete", value: %{id: <%= schema.singular %>.id})} data-confirm="Are you sure?">Delete</.link></span>
         </td>
       </tr>
@@ -36,4 +36,4 @@
   </tbody>
 </table>
 
-<span><.link patch={Routes.<%= schema.route_helper %>_index_path(@socket, :new)}>New <%= schema.human_singular %></.link></span>
+<span><.link patch={~p"<%= schema.route_path %>/new"}>New <%= schema.human_singular %></.link></span>
diff --git a/priv/templates/phx.gen.live/show.html.heex b/priv/templates/phx.gen.live/show.html.heex
index bd1f93acb..8e3da20d0 100644
--- a/priv/templates/phx.gen.live/show.html.heex
+++ b/priv/templates/phx.gen.live/show.html.heex
@@ -1,14 +1,14 @@
 <h1>Show <%= schema.human_singular %></h1>
 
 <%%= if @live_action in [:edit] do %>
-  <.modal return_to={Routes.<%= schema.route_helper %>_show_path(@socket, :show, @<%= schema.singular %>)}>
+  <.modal return_to={~p"<%= schema.route_path %>/#{@<%= schema.singular %>}"}>
     <.live_component
       module={<%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent}
       id={@<%= schema.singular %>.id}
       title={@page_title}
       action={@live_action}
       <%= schema.singular %>={@<%= schema.singular %>}
-      return_to={Routes.<%= schema.route_helper %>_show_path(@socket, :show, @<%= schema.singular %>)}
+      return_to={~p"<%= schema.route_path %>/#{@<%= schema.singular %>}"}
     />
   </.modal>
 <%% end %>
@@ -22,5 +22,5 @@
 <% end %>
 </ul>
 
-<span><.link patch={Routes.<%= schema.route_helper %>_show_path(@socket, :edit, @<%= schema.singular %>)} class="button">Edit</.link></span> |
-<span><.link navigate={Routes.<%= schema.route_helper %>_index_path(@socket, :index)}>Back</.link></span>
+<span><.link patch={~p"<%= schema.route_path %>/#{@<%= schema.singular %>}/show/edit"} class="button">Edit</.link></span> |
+<span><.link navigate={~p"<%= schema.route_path %>"}>Back</.link></span>


Test patch:
diff --git a/installer/templates/phx_test/controllers/page_controller_test.exs b/installer/templates/phx_test/controllers/page_controller_test.exs
index 9a9c7991d..3957cc8d3 100644
--- a/installer/templates/phx_test/controllers/page_controller_test.exs
+++ b/installer/templates/phx_test/controllers/page_controller_test.exs
@@ -2,7 +2,7 @@ defmodule <%= @web_namespace %>.PageControllerTest do
   use <%= @web_namespace %>.ConnCase
 
   test "GET /", %{conn: conn} do
-    conn = get(conn, "/")
+    conn = get(conn, ~p"/")
     assert html_response(conn, 200) =~ "Welcome to Phoenix!"
   end
 end
diff --git a/installer/templates/phx_test/live/page_live_test.exs b/installer/templates/phx_test/live/page_live_test.exs
index ea6bae956..98693942f 100644
--- a/installer/templates/phx_test/live/page_live_test.exs
+++ b/installer/templates/phx_test/live/page_live_test.exs
@@ -4,7 +4,7 @@ defmodule <%= @web_namespace %>.PageLiveTest do
   import Phoenix.LiveViewTest
 
   test "disconnected and connected render", %{conn: conn} do
-    conn = get(conn, "/")
+    conn = get(conn, ~p"/")
     disconnected_html = html_response(conn, 200)
     {:ok, _live, connected_html} = live(conn)
 
diff --git a/installer/templates/phx_test/support/conn_case.ex b/installer/templates/phx_test/support/conn_case.ex
index b74c3756a..4da9548a3 100644
--- a/installer/templates/phx_test/support/conn_case.ex
+++ b/installer/templates/phx_test/support/conn_case.ex
@@ -19,15 +19,18 @@ defmodule <%= @web_namespace %>.ConnCase do
 
   using do
     quote do
+      # The default endpoint for testing
+      @endpoint <%= @endpoint_module %>
+
+      use Phoenix.VerifiedRoutes,
+        endpoint: @endpoint,
+        router: <%= @web_namespace %>.Router,
+        statics: <%= @web_namespace %>.static_paths()
+
       # Import conveniences for testing with connections
       import Plug.Conn
       import Phoenix.ConnTest
       import <%= @web_namespace %>.ConnCase
-
-      alias <%= @web_namespace %>.Router.Helpers, as: Routes
-
-      # The default endpoint for testing
-      @endpoint <%= @endpoint_module %>
     end
   end<%= if @ecto do %>
 
diff --git a/priv/templates/phx.gen.html/controller_test.exs b/priv/templates/phx.gen.html/controller_test.exs
index 0ac312e5e..398cb99e5 100644
--- a/priv/templates/phx.gen.html/controller_test.exs
+++ b/priv/templates/phx.gen.html/controller_test.exs
@@ -9,31 +9,31 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
 
   describe "index" do
     test "lists all <%= schema.plural %>", %{conn: conn} do
-      conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :index))
+      conn = get(conn, ~p"<%= schema.route_path %>")
       assert html_response(conn, 200) =~ "Listing <%= schema.human_plural %>"
     end
   end
 
   describe "new <%= schema.singular %>" do
     test "renders form", %{conn: conn} do
-      conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :new))
+      conn = get(conn, ~p"<%= schema.route_path %>/new")
       assert html_response(conn, 200) =~ "New <%= schema.human_singular %>"
     end
   end
 
   describe "create <%= schema.singular %>" do
     test "redirects to show when data is valid", %{conn: conn} do
-      conn = post(conn, Routes.<%= schema.route_helper %>_path(conn, :create), <%= schema.singular %>: @create_attrs)
+      conn = post(conn,  ~p"<%= schema.route_path %>", <%= schema.singular %>: @create_attrs)
 
       assert %{id: id} = redirected_params(conn)
-      assert redirected_to(conn) == Routes.<%= schema.route_helper %>_path(conn, :show, id)
+      assert redirected_to(conn) == ~p"<%= schema.route_path %>/#{id}"
 
-      conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, id))
+      conn = get(conn, ~p"<%= schema.route_path %>/#{id}")
       assert html_response(conn, 200) =~ "Show <%= schema.human_singular %>"
     end
 
     test "renders errors when data is invalid", %{conn: conn} do
-      conn = post(conn, Routes.<%= schema.route_helper %>_path(conn, :create), <%= schema.singular %>: @invalid_attrs)
+      conn = post(conn, ~p"<%= schema.route_path %>", <%= schema.singular %>: @invalid_attrs)
       assert html_response(conn, 200) =~ "New <%= schema.human_singular %>"
     end
   end
@@ -42,7 +42,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
     setup [:create_<%= schema.singular %>]
 
     test "renders form for editing chosen <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
-      conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :edit, <%= schema.singular %>))
+      conn = get(conn, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}/edit")
       assert html_response(conn, 200) =~ "Edit <%= schema.human_singular %>"
     end
   end
@@ -51,16 +51,16 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
     setup [:create_<%= schema.singular %>]
 
     test "redirects when data is valid", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
-      conn = put(conn, Routes.<%= schema.route_helper %>_path(conn, :update, <%= schema.singular %>), <%= schema.singular %>: @update_attrs)
-      assert redirected_to(conn) == Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>)
+      conn = put(conn, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}", <%= schema.singular %>: @update_attrs)
+      assert redirected_to(conn) == ~p"<%= schema.route_path %>/#{<%= schema.singular %>}"
 
-      conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))<%= if schema.string_attr do %>
+      conn = get(conn, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}")<%= if schema.string_attr do %>
       assert html_response(conn, 200) =~ <%= inspect Mix.Phoenix.Schema.default_param(schema, :update) %><% else %>
       assert html_response(conn, 200)<% end %>
     end
 
     test "renders errors when data is invalid", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
-      conn = put(conn, Routes.<%= schema.route_helper %>_path(conn, :update, <%= schema.singular %>), <%= schema.singular %>: @invalid_attrs)
+      conn = put(conn, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}", <%= schema.singular %>: @invalid_attrs)
       assert html_response(conn, 200) =~ "Edit <%= schema.human_singular %>"
     end
   end
@@ -69,11 +69,11 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
     setup [:create_<%= schema.singular %>]
 
     test "deletes chosen <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
-      conn = delete(conn, Routes.<%= schema.route_helper %>_path(conn, :delete, <%= schema.singular %>))
-      assert redirected_to(conn) == Routes.<%= schema.route_helper %>_path(conn, :index)
+      conn = delete(conn, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}")
+      assert redirected_to(conn) == ~p"<%= schema.route_path %>"
 
       assert_error_sent 404, fn ->
-        get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))
+        get(conn, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}")
       end
     end
   end
diff --git a/priv/templates/phx.gen.json/controller_test.exs b/priv/templates/phx.gen.json/controller_test.exs
index 0208cc436..1aa23eb2e 100644
--- a/priv/templates/phx.gen.json/controller_test.exs
+++ b/priv/templates/phx.gen.json/controller_test.exs
@@ -19,17 +19,17 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
 
   describe "index" do
     test "lists all <%= schema.plural %>", %{conn: conn} do
-      conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :index))
+      conn = get(conn, ~p"<%= schema.api_route_path %>")
       assert json_response(conn, 200)["data"] == []
     end
   end
 
   describe "create <%= schema.singular %>" do
     test "renders <%= schema.singular %> when data is valid", %{conn: conn} do
-      conn = post(conn, Routes.<%= schema.route_helper %>_path(conn, :create), <%= schema.singular %>: @create_attrs)
+      conn = post(conn, ~p"<%= schema.api_route_path %>", <%= schema.singular %>: @create_attrs)
       assert %{"id" => id} = json_response(conn, 201)["data"]
 
-      conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, id))
+      conn = get(conn, ~p"<%= schema.api_route_path %>/#{id}")
 
       assert %{
                "id" => ^id<%= for {key, val} <- schema.params.create |> Phoenix.json_library().encode!() |> Phoenix.json_library().decode!() do %>,
@@ -38,7 +38,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
     end
 
     test "renders errors when data is invalid", %{conn: conn} do
-      conn = post(conn, Routes.<%= schema.route_helper %>_path(conn, :create), <%= schema.singular %>: @invalid_attrs)
+      conn = post(conn, ~p"<%= schema.api_route_path %>", <%= schema.singular %>: @invalid_attrs)
       assert json_response(conn, 422)["errors"] != %{}
     end
   end
@@ -47,10 +47,10 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
     setup [:create_<%= schema.singular %>]
 
     test "renders <%= schema.singular %> when data is valid", %{conn: conn, <%= schema.singular %>: %<%= inspect schema.alias %>{id: id} = <%= schema.singular %>} do
-      conn = put(conn, Routes.<%= schema.route_helper %>_path(conn, :update, <%= schema.singular %>), <%= schema.singular %>: @update_attrs)
+      conn = put(conn, ~p"<%= schema.api_route_path %>/#{<%= schema.singular %>}", <%= schema.singular %>: @update_attrs)
       assert %{"id" => ^id} = json_response(conn, 200)["data"]
 
-      conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, id))
+      conn = get(conn, ~p"<%= schema.api_route_path %>/#{id}")
 
       assert %{
                "id" => ^id<%= for {key, val} <- schema.params.update |> Phoenix.json_library().encode!() |> Phoenix.json_library().decode!() do %>,
@@ -59,7 +59,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
     end
 
     test "renders errors when data is invalid", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
-      conn = put(conn, Routes.<%= schema.route_helper %>_path(conn, :update, <%= schema.singular %>), <%= schema.singular %>: @invalid_attrs)
+      conn = put(conn, ~p"<%= schema.api_route_path %>/#{<%= schema.singular %>}", <%= schema.singular %>: @invalid_attrs)
       assert json_response(conn, 422)["errors"] != %{}
     end
   end
@@ -68,11 +68,11 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
     setup [:create_<%= schema.singular %>]
 
     test "deletes chosen <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
-      conn = delete(conn, Routes.<%= schema.route_helper %>_path(conn, :delete, <%= schema.singular %>))
+      conn = delete(conn, ~p"<%= schema.api_route_path %>/#{<%= schema.singular %>}")
       assert response(conn, 204)
 
       assert_error_sent 404, fn ->
-        get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))
+        get(conn, ~p"<%= schema.api_route_path %>/#{<%= schema.singular %>}")
       end
     end
   end
diff --git a/priv/templates/phx.gen.live/live_test.exs b/priv/templates/phx.gen.live/live_test.exs
index d71e4b30a..21181d767 100644
--- a/priv/templates/phx.gen.live/live_test.exs
+++ b/priv/templates/phx.gen.live/live_test.exs
@@ -17,19 +17,19 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
     setup [:create_<%= schema.singular %>]
 
     test "lists all <%= schema.plural %>", <%= if schema.string_attr do %>%{conn: conn, <%= schema.singular %>: <%= schema.singular %>}<% else %>%{conn: conn}<% end %> do
-      {:ok, _index_live, html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
+      {:ok, _index_live, html} = live(conn, ~p"<%= schema.route_path %>")
 
       assert html =~ "Listing <%= schema.human_plural %>"<%= if schema.string_attr do %>
       assert html =~ <%= schema.singular %>.<%= schema.string_attr %><% end %>
     end
 
     test "saves new <%= schema.singular %>", %{conn: conn} do
-      {:ok, index_live, _html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
+      {:ok, index_live, _html} = live(conn, ~p"<%= schema.route_path %>")
 
       assert index_live |> element("a", "New <%= schema.human_singular %>") |> render_click() =~
                "New <%= schema.human_singular %>"
 
-      assert_patch(index_live, Routes.<%= schema.route_helper %>_index_path(conn, :new))
+      assert_patch(index_live, ~p"<%= schema.route_path %>/new")
 
       assert index_live
              |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs)
@@ -39,19 +39,19 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
         index_live
         |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @create_attrs)
         |> render_submit()
-        |> follow_redirect(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
+        |> follow_redirect(conn, ~p"<%= schema.route_path %>")
 
       assert html =~ "<%= schema.human_singular %> created successfully"<%= if schema.string_attr do %>
       assert html =~ "some <%= schema.string_attr %>"<% end %>
     end
 
     test "updates <%= schema.singular %> in listing", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
-      {:ok, index_live, _html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
+      {:ok, index_live, _html} = live(conn, ~p"<%= schema.route_path %>")
 
       assert index_live |> element("#<%= schema.singular %>-#{<%= schema.singular %>.id} a", "Edit") |> render_click() =~
                "Edit <%= schema.human_singular %>"
 
-      assert_patch(index_live, Routes.<%= schema.route_helper %>_index_path(conn, :edit, <%= schema.singular %>))
+      assert_patch(index_live, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}/edit")
 
       assert index_live
              |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs)
@@ -61,14 +61,14 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
         index_live
         |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @update_attrs)
         |> render_submit()
-        |> follow_redirect(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
+        |> follow_redirect(conn, ~p"<%= schema.route_path %>")
 
       assert html =~ "<%= schema.human_singular %> updated successfully"<%= if schema.string_attr do %>
       assert html =~ "some updated <%= schema.string_attr %>"<% end %>
     end
 
     test "deletes <%= schema.singular %> in listing", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
-      {:ok, index_live, _html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
+      {:ok, index_live, _html} = live(conn, ~p"<%= schema.route_path %>")
 
       assert index_live |> element("#<%= schema.singular %>-#{<%= schema.singular %>.id} a", "Delete") |> render_click()
       refute has_element?(index_live, "#<%= schema.singular %>-#{<%= schema.singular %>.id}")
@@ -79,19 +79,19 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
     setup [:create_<%= schema.singular %>]
 
     test "displays <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
-      {:ok, _show_live, html} = live(conn, Routes.<%= schema.route_helper %>_show_path(conn, :show, <%= schema.singular %>))
+      {:ok, _show_live, html} = live(conn, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}")
 
       assert html =~ "Show <%= schema.human_singular %>"<%= if schema.string_attr do %>
       assert html =~ <%= schema.singular %>.<%= schema.string_attr %><% end %>
     end
 
     test "updates <%= schema.singular %> within modal", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
-      {:ok, show_live, _html} = live(conn, Routes.<%= schema.route_helper %>_show_path(conn, :show, <%= schema.singular %>))
+      {:ok, show_live, _html} = live(conn, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}")
 
       assert show_live |> element("a", "Edit") |> render_click() =~
                "Edit <%= schema.human_singular %>"
 
-      assert_patch(show_live, Routes.<%= schema.route_helper %>_show_path(conn, :edit, <%= schema.singular %>))
+      assert_patch(show_live, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}/show/edit")
 
       assert show_live
              |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs)
@@ -101,7 +101,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
         show_live
         |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @update_attrs)
         |> render_submit()
-        |> follow_redirect(conn, Routes.<%= schema.route_helper %>_show_path(conn, :show, <%= schema.singular %>))
+        |> follow_redirect(conn, ~p"<%= schema.route_path %>/#{<%= schema.singular %>}")
 
       assert html =~ "<%= schema.human_singular %> updated successfully"<%= if schema.string_attr do %>
       assert html =~ "some updated <%= schema.string_attr %>"<% end %>
diff --git a/test/mix/tasks/phx.gen.html_test.exs b/test/mix/tasks/phx.gen.html_test.exs
index 9328b72ac..bd91ad5c5 100644
--- a/test/mix/tasks/phx.gen.html_test.exs
+++ b/test/mix/tasks/phx.gen.html_test.exs
@@ -84,7 +84,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do
 
       assert_file "test/phoenix_web/controllers/post_controller_test.exs", fn file ->
         assert file =~ "defmodule PhoenixWeb.PostControllerTest"
-        assert file =~ "Routes.post_path(conn"
+        assert file =~ ~s|~p"/posts|
       end
 
       assert [path] = Path.wildcard("priv/repo/migrations/*_create_posts.exs")
@@ -104,7 +104,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do
         assert file =~ "Blog.update_post"
         assert file =~ "Blog.delete_post"
         assert file =~ "Blog.change_post"
-        assert file =~ "redirect(to: Routes.post_path(conn"
+        assert file =~ ~s|redirect(to: ~p"/posts|
       end
 
       assert_file "lib/phoenix_web/views/post_view.ex", fn file ->
@@ -112,19 +112,19 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do
       end
 
       assert_file "lib/phoenix_web/templates/post/edit.html.heex", fn file ->
-        assert file =~ "Routes.post_path(@conn"
+        assert file =~ ~s|~p"/posts|
       end
 
       assert_file "lib/phoenix_web/templates/post/index.html.heex", fn file ->
-        assert file =~ "Routes.post_path(@conn"
+        assert file =~ ~s|~p"/posts|
       end
 
       assert_file "lib/phoenix_web/templates/post/new.html.heex", fn file ->
-        assert file =~ "Routes.post_path(@conn"
+        assert file =~ ~s|~p"/posts|
       end
 
       assert_file "lib/phoenix_web/templates/post/show.html.heex", fn file ->
-        assert file =~ "Routes.post_path(@conn"
+        assert file =~ ~s|~p"/posts|
       end
 
       assert_file "lib/phoenix_web/templates/post/form.html.heex", fn file ->
@@ -184,7 +184,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do
         assert file =~ "Blog.update_comment"
         assert file =~ "Blog.delete_comment"
         assert file =~ "Blog.change_comment"
-        assert file =~ "redirect(to: Routes.comment_path(conn"
+        assert file =~ ~s|redirect(to: ~p"/comments|
       end
 
       assert_receive {:mix_shell, :info, ["""
@@ -230,31 +230,31 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do
 
       assert_file "test/phoenix_web/controllers/blog/post_controller_test.exs", fn file ->
         assert file =~ "defmodule PhoenixWeb.Blog.PostControllerTest"
-        assert file =~ "Routes.blog_post_path(conn"
+        assert file =~ ~s|~p"/blog/posts|
       end
 
       assert_file "lib/phoenix_web/controllers/blog/post_controller.ex", fn file ->
         assert file =~ "defmodule PhoenixWeb.Blog.PostController"
         assert file =~ "use PhoenixWeb, :controller"
-        assert file =~ "redirect(to: Routes.blog_post_path(conn"
+        assert file =~ ~s|redirect(to: ~p"/blog/posts|
       end
 
       assert_file "lib/phoenix_web/templates/blog/post/form.html.heex"
 
       assert_file "lib/phoenix_web/templates/blog/post/edit.html.heex", fn file ->
-        assert file =~ "Routes.blog_post_path(@conn"
+        assert file =~ ~s|~p"/blog/posts|
       end
 
       assert_file "lib/phoenix_web/templates/blog/post/index.html.heex", fn file ->
-        assert file =~ "Routes.blog_post_path(@conn"
+        assert file =~ ~s|~p"/blog/posts|
       end
 
       assert_file "lib/phoenix_web/templates/blog/post/new.html.heex", fn file ->
-        assert file =~ "Routes.blog_post_path(@conn"
+        assert file =~ ~s|~p"/blog/posts|
       end
 
       assert_file "lib/phoenix_web/templates/blog/post/show.html.heex", fn file ->
-        assert file =~ "Routes.blog_post_path(@conn"
+        assert file =~ ~s|~p"/blog/posts|
       end
 
       assert_file "lib/phoenix_web/views/blog/post_view.ex", fn file ->
diff --git a/test/mix/tasks/phx.gen.json_test.exs b/test/mix/tasks/phx.gen.json_test.exs
index b69297160..fc67daf07 100644
--- a/test/mix/tasks/phx.gen.json_test.exs
+++ b/test/mix/tasks/phx.gen.json_test.exs
@@ -105,7 +105,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do
         assert file =~ "Blog.create_post"
         assert file =~ "Blog.update_post"
         assert file =~ "Blog.delete_post"
-        assert file =~ " Routes.post_path(conn"
+        assert file =~ ~s|~p"/api/posts|
       end
 
       assert_receive {:mix_shell, :info, ["""
@@ -162,13 +162,13 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do
 
       assert_file "test/phoenix_web/controllers/blog/post_controller_test.exs", fn file ->
         assert file =~ "defmodule PhoenixWeb.Blog.PostControllerTest"
-        assert file =~ " Routes.blog_post_path(conn"
+        assert file =~ ~s|~p"/api/blog/posts|
       end
 
       assert_file "lib/phoenix_web/controllers/blog/post_controller.ex", fn file ->
         assert file =~ "defmodule PhoenixWeb.Blog.PostController"
         assert file =~ "use PhoenixWeb, :controller"
-        assert file =~ " Routes.blog_post_path(conn"
+        assert file =~ ~s|~p"/api/blog/posts|
       end
 
       assert_file "lib/phoenix_web/views/blog/post_view.ex", fn file ->
diff --git a/test/mix/tasks/phx.gen.live_test.exs b/test/mix/tasks/phx.gen.live_test.exs
index f397e0b07..d6c80caf9 100644
--- a/test/mix/tasks/phx.gen.live_test.exs
+++ b/test/mix/tasks/phx.gen.live_test.exs
@@ -91,11 +91,11 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do
       end
 
       assert_file "lib/phoenix_web/live/post_live/index.html.heex", fn file ->
-        assert file =~ "Routes.post_index_path(@socket, :index)"
+        assert file =~ ~S|~p"/posts"|
       end
 
       assert_file "lib/phoenix_web/live/post_live/show.html.heex", fn file ->
-        assert file =~ "Routes.post_index_path(@socket, :index)"
+        assert file =~ ~S|~p"/posts"|
       end
 
       assert_file "lib/phoenix_web/live/post_live/form_component.html.heex", fn file ->
@@ -130,10 +130,10 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do
 
       assert_file "test/phoenix_web/live/post_live_test.exs", fn file ->
         assert file =~ ~r"@invalid_attrs.*popular: false"
-        assert file =~ "Routes.post_index_path(conn, :index)"
-        assert file =~ "Routes.post_index_path(conn, :new)"
-        assert file =~ "Routes.post_show_path(conn, :show, post)"
-        assert file =~ "Routes.post_show_path(conn, :edit, post)"
+        assert file =~ ~S|~p"/posts"|
+        assert file =~ ~S|~p"/posts/new"|
+        assert file =~ ~S|~p"/posts/#{post}"|
+        assert file =~ ~S|~p"/posts/#{post}/show/edit"|
       end
 
       send self(), {:mix_shell_input, :yes?, true}
@@ -239,25 +239,25 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do
       end
 
       assert_file "lib/phoenix_web/live/blog/post_live/index.html.heex", fn file ->
-        assert file =~ "Routes.blog_post_index_path(@socket, :index)"
-        assert file =~ "Routes.blog_post_index_path(@socket, :edit, post)"
-        assert file =~ "Routes.blog_post_index_path(@socket, :new)"
-        assert file =~ "Routes.blog_post_show_path(@socket, :show, post)"
+        assert file =~ ~S|~p"/blog/posts"|
+        assert file =~ ~S|~p"/blog/posts/#{post}/edit"|
+        assert file =~ ~S|~p"/blog/posts/new"|
+        assert file =~ ~S|~p"/blog/posts/#{post}"|
       end
 
       assert_file "lib/phoenix_web/live/blog/post_live/show.html.heex", fn file ->
-        assert file =~ "Routes.blog_post_index_path(@socket, :index)"
-        assert file =~ "Routes.blog_post_show_path(@socket, :show, @post)"
-        assert file =~ "Routes.blog_post_show_path(@socket, :edit, @post)"
+        assert file =~ ~S|~p"/blog/posts"|
+        assert file =~ ~S|~p"/blog/posts/#{@post}"|
+        assert file =~ ~S|~p"/blog/posts/#{@post}/show/edit"|
       end
 
       assert_file "lib/phoenix_web/live/blog/post_live/form_component.html.heex"
 
       assert_file "test/phoenix_web/live/blog/post_live_test.exs", fn file ->
-        assert file =~ "Routes.blog_post_index_path(conn, :index)"
-        assert file =~ "Routes.blog_post_index_path(conn, :new)"
-        assert file =~ "Routes.blog_post_show_path(conn, :show, post)"
-        assert file =~ "Routes.blog_post_show_path(conn, :edit, post)"
+        assert file =~ ~S|~p"/blog/posts"|
+        assert file =~ ~S|~p"/blog/posts/new"|
+        assert file =~ ~S|~p"/blog/posts/#{post}"|
+        assert file =~ ~S|~p"/blog/posts/#{post}/show/edit"|
       end
 
       assert_receive {:mix_shell, :info, ["""